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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(parent: nil, operator: nil, name: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parent:, operator:, name:, location:) ⇒ Field
constructor
A new instance of Field.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(parent:, operator:, name:, location:) ⇒ Field
Returns a new instance of Field.
5206 5207 5208 5209 5210 5211 5212 |
# File 'lib/syntax_tree/node.rb', line 5206 def initialize(parent:, operator:, name:, location:) @parent = parent @operator = operator @name = name @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5204 5205 5206 |
# File 'lib/syntax_tree/node.rb', line 5204 def comments @comments end |
#name ⇒ Object (readonly)
- Const | Ident
-
the name of the field being assigned
5201 5202 5203 |
# File 'lib/syntax_tree/node.rb', line 5201 def name @name end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used for the assignment
5198 5199 5200 |
# File 'lib/syntax_tree/node.rb', line 5198 def operator @operator end |
#parent ⇒ Object (readonly)
- untyped
-
the parent object that owns the field being assigned
5195 5196 5197 |
# File 'lib/syntax_tree/node.rb', line 5195 def parent @parent end |
Instance Method Details
#===(other) ⇒ Object
5255 5256 5257 5258 |
# File 'lib/syntax_tree/node.rb', line 5255 def ===(other) other.is_a?(Field) && parent === other.parent && operator === other.operator && name === other.name end |
#accept(visitor) ⇒ Object
5214 5215 5216 |
# File 'lib/syntax_tree/node.rb', line 5214 def accept(visitor) visitor.visit_field(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5218 5219 5220 |
# File 'lib/syntax_tree/node.rb', line 5218 def child_nodes [parent, (operator if operator != :"::"), name] end |
#copy(parent: nil, operator: nil, name: nil, location: nil) ⇒ Object
5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 |
# File 'lib/syntax_tree/node.rb', line 5222 def copy(parent: nil, operator: nil, name: nil, location: nil) node = Field.new( parent: parent || self.parent, operator: operator || self.operator, name: name || self.name, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
5237 5238 5239 5240 5241 5242 5243 5244 5245 |
# File 'lib/syntax_tree/node.rb', line 5237 def deconstruct_keys(_keys) { parent: parent, operator: operator, name: name, location: location, comments: comments } end |
#format(q) ⇒ Object
5247 5248 5249 5250 5251 5252 5253 |
# File 'lib/syntax_tree/node.rb', line 5247 def format(q) q.group do q.format(parent) q.format(CallOperatorFormatter.new(operator), stackable: false) q.format(name) end end |