Class: SyntaxTree::Defined
- Inherits:
-
Object
- Object
- SyntaxTree::Defined
- Defined in:
- lib/syntax_tree.rb
Overview
Defined represents the use of the defined? operator. It can be used with and without parentheses.
defined?(variable)
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- untyped
-
the value being sent to the keyword.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Defined
constructor
A new instance of Defined.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Defined
Returns a new instance of Defined.
4266 4267 4268 4269 4270 |
# File 'lib/syntax_tree.rb', line 4266 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4264 4265 4266 |
# File 'lib/syntax_tree.rb', line 4264 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4261 4262 4263 |
# File 'lib/syntax_tree.rb', line 4261 def location @location end |
#value ⇒ Object (readonly)
- untyped
-
the value being sent to the keyword
4258 4259 4260 |
# File 'lib/syntax_tree.rb', line 4258 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
4272 4273 4274 |
# File 'lib/syntax_tree.rb', line 4272 def child_nodes [value] end |
#format(q) ⇒ Object
4276 4277 4278 4279 4280 4281 4282 4283 4284 |
# File 'lib/syntax_tree.rb', line 4276 def format(q) q.group(0, "defined?(", ")") do q.indent do q.breakable("") q.format(value) end q.breakable("") end end |
#pretty_print(q) ⇒ Object
4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 |
# File 'lib/syntax_tree.rb', line 4286 def pretty_print(q) q.group(2, "(", ")") do q.text("defined") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
4297 4298 4299 4300 4301 |
# File 'lib/syntax_tree.rb', line 4297 def to_json(*opts) { type: :defined, value: value, loc: location, cmts: comments }.to_json( *opts ) end |