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
Constructor Details
#initialize(parent:, operator:, name:, location:, comments: []) ⇒ Field
Returns a new instance of Field.
4375 4376 4377 4378 4379 4380 4381 |
# File 'lib/syntax_tree/node.rb', line 4375 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
4373 4374 4375 |
# File 'lib/syntax_tree/node.rb', line 4373 def comments @comments end |
#name ⇒ Object (readonly)
- Const | Ident
-
the name of the field being assigned
4370 4371 4372 |
# File 'lib/syntax_tree/node.rb', line 4370 def name @name end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used for the assignment
4367 4368 4369 |
# File 'lib/syntax_tree/node.rb', line 4367 def operator @operator end |
#parent ⇒ Object (readonly)
- untyped
-
the parent object that owns the field being assigned
4364 4365 4366 |
# File 'lib/syntax_tree/node.rb', line 4364 def parent @parent end |
Instance Method Details
#accept(visitor) ⇒ Object
4383 4384 4385 |
# File 'lib/syntax_tree/node.rb', line 4383 def accept(visitor) visitor.visit_field(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4387 4388 4389 |
# File 'lib/syntax_tree/node.rb', line 4387 def child_nodes [parent, (operator if operator != :"::"), name] end |
#deconstruct_keys(keys) ⇒ Object
4393 4394 4395 4396 4397 4398 4399 4400 4401 |
# File 'lib/syntax_tree/node.rb', line 4393 def deconstruct_keys(keys) { parent: parent, operator: operator, name: name, location: location, comments: comments } end |
#format(q) ⇒ Object
4403 4404 4405 4406 4407 4408 4409 |
# File 'lib/syntax_tree/node.rb', line 4403 def format(q) q.group do q.format(parent) q.format(CallOperatorFormatter.new(operator), stackable: false) q.format(name) end end |