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.
4554 4555 4556 4557 4558 |
# File 'lib/syntax_tree.rb', line 4554 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
4552 4553 4554 |
# File 'lib/syntax_tree.rb', line 4552 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4549 4550 4551 |
# File 'lib/syntax_tree.rb', line 4549 def location @location end |
#value ⇒ Object (readonly)
- untyped
-
the value being sent to the keyword
4546 4547 4548 |
# File 'lib/syntax_tree.rb', line 4546 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
4560 4561 4562 |
# File 'lib/syntax_tree.rb', line 4560 def child_nodes [value] end |
#format(q) ⇒ Object
4564 4565 4566 4567 4568 4569 4570 4571 4572 |
# File 'lib/syntax_tree.rb', line 4564 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
4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 |
# File 'lib/syntax_tree.rb', line 4574 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
4585 4586 4587 4588 4589 |
# File 'lib/syntax_tree.rb', line 4585 def to_json(*opts) { type: :defined, value: value, loc: location, cmts: comments }.to_json( *opts ) end |