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.
4723 4724 4725 4726 4727 |
# File 'lib/syntax_tree.rb', line 4723 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
4721 4722 4723 |
# File 'lib/syntax_tree.rb', line 4721 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4718 4719 4720 |
# File 'lib/syntax_tree.rb', line 4718 def location @location end |
#value ⇒ Object (readonly)
- untyped
-
the value being sent to the keyword
4715 4716 4717 |
# File 'lib/syntax_tree.rb', line 4715 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
4729 4730 4731 |
# File 'lib/syntax_tree.rb', line 4729 def child_nodes [value] end |
#format(q) ⇒ Object
4733 4734 4735 4736 4737 4738 4739 4740 4741 |
# File 'lib/syntax_tree.rb', line 4733 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
4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 |
# File 'lib/syntax_tree.rb', line 4743 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
4754 4755 4756 4757 4758 |
# File 'lib/syntax_tree.rb', line 4754 def to_json(*opts) { type: :defined, value: value, loc: location, cmts: comments }.to_json( *opts ) end |