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.
4012 4013 4014 4015 4016 4017 4018 |
# File 'lib/syntax_tree/node.rb', line 4012 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
4010 4011 4012 |
# File 'lib/syntax_tree/node.rb', line 4010 def comments @comments end |
#name ⇒ Object (readonly)
- Const | Ident
-
the name of the field being assigned
4007 4008 4009 |
# File 'lib/syntax_tree/node.rb', line 4007 def name @name end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used for the assignment
4004 4005 4006 |
# File 'lib/syntax_tree/node.rb', line 4004 def operator @operator end |
#parent ⇒ Object (readonly)
- untyped
-
the parent object that owns the field being assigned
4001 4002 4003 |
# File 'lib/syntax_tree/node.rb', line 4001 def parent @parent end |
Instance Method Details
#accept(visitor) ⇒ Object
4020 4021 4022 |
# File 'lib/syntax_tree/node.rb', line 4020 def accept(visitor) visitor.visit_field(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4024 4025 4026 |
# File 'lib/syntax_tree/node.rb', line 4024 def child_nodes [parent, (operator if operator != :"::"), name] end |
#deconstruct_keys(keys) ⇒ Object
4030 4031 4032 4033 4034 4035 4036 4037 4038 |
# File 'lib/syntax_tree/node.rb', line 4030 def deconstruct_keys(keys) { parent: parent, operator: operator, name: name, location: location, comments: comments } end |
#format(q) ⇒ Object
4040 4041 4042 4043 4044 4045 4046 |
# File 'lib/syntax_tree/node.rb', line 4040 def format(q) q.group do q.format(parent) q.format(CallOperatorFormatter.new(operator), stackable: false) q.format(name) end end |