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.
4485 4486 4487 4488 4489 4490 4491 |
# File 'lib/syntax_tree/node.rb', line 4485 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
4483 4484 4485 |
# File 'lib/syntax_tree/node.rb', line 4483 def comments @comments end |
#name ⇒ Object (readonly)
- Const | Ident
-
the name of the field being assigned
4480 4481 4482 |
# File 'lib/syntax_tree/node.rb', line 4480 def name @name end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used for the assignment
4477 4478 4479 |
# File 'lib/syntax_tree/node.rb', line 4477 def operator @operator end |
#parent ⇒ Object (readonly)
- untyped
-
the parent object that owns the field being assigned
4474 4475 4476 |
# File 'lib/syntax_tree/node.rb', line 4474 def parent @parent end |
Instance Method Details
#accept(visitor) ⇒ Object
4493 4494 4495 |
# File 'lib/syntax_tree/node.rb', line 4493 def accept(visitor) visitor.visit_field(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4497 4498 4499 |
# File 'lib/syntax_tree/node.rb', line 4497 def child_nodes [parent, (operator if operator != :"::"), name] end |
#deconstruct_keys(_keys) ⇒ Object
4503 4504 4505 4506 4507 4508 4509 4510 4511 |
# File 'lib/syntax_tree/node.rb', line 4503 def deconstruct_keys(_keys) { parent: parent, operator: operator, name: name, location: location, comments: comments } end |
#format(q) ⇒ Object
4513 4514 4515 4516 4517 4518 4519 |
# File 'lib/syntax_tree/node.rb', line 4513 def format(q) q.group do q.format(parent) q.format(CallOperatorFormatter.new(operator), stackable: false) q.format(name) end end |