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