Class: SyntaxTree::Field
Overview
Field is always the child of an assignment. It represents assigning to a “field” on an object.
object.variable = value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#name ⇒ Object
readonly
- Const | Ident
-
the name of the field being assigned.
-
#operator ⇒ Object
readonly
- :“::” | Op | Period
-
the operator being used for the assignment.
-
#parent ⇒ Object
readonly
- untyped
-
the parent object that owns the field being assigned.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parent:, operator:, name:, location:, comments: []) ⇒ Field
constructor
A new instance of Field.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(parent:, operator:, name:, location:, comments: []) ⇒ Field
Returns a new instance of Field.
4594 4595 4596 4597 4598 4599 4600 |
# File 'lib/syntax_tree/node.rb', line 4594 def initialize(parent:, operator:, name:, location:, comments: []) @parent = parent @operator = operator @name = name @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4592 4593 4594 |
# File 'lib/syntax_tree/node.rb', line 4592 def comments @comments end |
#name ⇒ Object (readonly)
- Const | Ident
-
the name of the field being assigned
4589 4590 4591 |
# File 'lib/syntax_tree/node.rb', line 4589 def name @name end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used for the assignment
4586 4587 4588 |
# File 'lib/syntax_tree/node.rb', line 4586 def operator @operator end |
#parent ⇒ Object (readonly)
- untyped
-
the parent object that owns the field being assigned
4583 4584 4585 |
# File 'lib/syntax_tree/node.rb', line 4583 def parent @parent end |
Instance Method Details
#accept(visitor) ⇒ Object
4602 4603 4604 |
# File 'lib/syntax_tree/node.rb', line 4602 def accept(visitor) visitor.visit_field(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4606 4607 4608 |
# File 'lib/syntax_tree/node.rb', line 4606 def child_nodes [parent, (operator if operator != :"::"), name] end |
#deconstruct_keys(_keys) ⇒ Object
4612 4613 4614 4615 4616 4617 4618 4619 4620 |
# File 'lib/syntax_tree/node.rb', line 4612 def deconstruct_keys(_keys) { parent: parent, operator: operator, name: name, location: location, comments: comments } end |
#format(q) ⇒ Object
4622 4623 4624 4625 4626 4627 4628 |
# File 'lib/syntax_tree/node.rb', line 4622 def format(q) q.group do q.format(parent) q.format(CallOperatorFormatter.new(operator), stackable: false) q.format(name) end end |