Class: SyntaxTree::VarField
- Inherits:
-
Object
- Object
- SyntaxTree::VarField
- Defined in:
- lib/syntax_tree.rb
Overview
VarField represents a variable that is being assigned a value. As such, it is always a child of an assignment type node.
variable = value
In the example above, the VarField node represents the variable
token.
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
- nil | Const | CVar | GVar | Ident | IVar
-
the target of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ VarField
constructor
A new instance of VarField.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ VarField
Returns a new instance of VarField.
12805 12806 12807 12808 12809 |
# File 'lib/syntax_tree.rb', line 12805 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
12803 12804 12805 |
# File 'lib/syntax_tree.rb', line 12803 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12800 12801 12802 |
# File 'lib/syntax_tree.rb', line 12800 def location @location end |
#value ⇒ Object (readonly)
- nil | Const | CVar | GVar | Ident | IVar
-
the target of this node
12797 12798 12799 |
# File 'lib/syntax_tree.rb', line 12797 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
12811 12812 12813 |
# File 'lib/syntax_tree.rb', line 12811 def child_nodes [value] end |
#format(q) ⇒ Object
12815 12816 12817 |
# File 'lib/syntax_tree.rb', line 12815 def format(q) q.format(value) if value end |
#pretty_print(q) ⇒ Object
12819 12820 12821 12822 12823 12824 12825 12826 12827 12828 |
# File 'lib/syntax_tree.rb', line 12819 def pretty_print(q) q.group(2, "(", ")") do q.text("var_field") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
12830 12831 12832 12833 12834 |
# File 'lib/syntax_tree.rb', line 12830 def to_json(*opts) { type: :var_field, value: value, loc: location, cmts: comments }.to_json( *opts ) end |