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
12724 12725 12726 12727 12728 |
# File 'lib/syntax_tree.rb', line 12724 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
12722 12723 12724 |
# File 'lib/syntax_tree.rb', line 12722 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12719 12720 12721 |
# File 'lib/syntax_tree.rb', line 12719 def location @location end |
#value ⇒ Object (readonly)
- nil | Const | CVar | GVar | Ident | IVar
-
the target of this node
12716 12717 12718 |
# File 'lib/syntax_tree.rb', line 12716 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
12730 12731 12732 |
# File 'lib/syntax_tree.rb', line 12730 def child_nodes [value] end |
#format(q) ⇒ Object
12734 12735 12736 |
# File 'lib/syntax_tree.rb', line 12734 def format(q) q.format(value) if value end |
#pretty_print(q) ⇒ Object
12738 12739 12740 12741 12742 12743 12744 12745 12746 12747 |
# File 'lib/syntax_tree.rb', line 12738 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
12749 12750 12751 12752 12753 |
# File 'lib/syntax_tree.rb', line 12749 def to_json(*opts) { type: :var_field, value: value, loc: location, cmts: comments }.to_json( *opts ) end |