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.
-
#location ⇒ Object
readonly
- Location
-
the location of 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.
Instance Method Summary collapse
- #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.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(parent:, operator:, name:, location:, comments: []) ⇒ Field
Returns a new instance of Field.
5145 5146 5147 5148 5149 5150 5151 |
# File 'lib/syntax_tree/node.rb', line 5145 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
5143 5144 5145 |
# File 'lib/syntax_tree/node.rb', line 5143 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5140 5141 5142 |
# File 'lib/syntax_tree/node.rb', line 5140 def location @location end |
#name ⇒ Object (readonly)
- Const | Ident
-
the name of the field being assigned
5137 5138 5139 |
# File 'lib/syntax_tree/node.rb', line 5137 def name @name end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used for the assignment
5134 5135 5136 |
# File 'lib/syntax_tree/node.rb', line 5134 def operator @operator end |
#parent ⇒ Object (readonly)
- untyped
-
the parent object that owns the field being assigned
5131 5132 5133 |
# File 'lib/syntax_tree/node.rb', line 5131 def parent @parent end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
5153 5154 5155 |
# File 'lib/syntax_tree/node.rb', line 5153 def child_nodes [parent, (operator if operator != :"::"), name] end |
#deconstruct_keys(keys) ⇒ Object
5159 5160 5161 5162 5163 5164 5165 5166 5167 |
# File 'lib/syntax_tree/node.rb', line 5159 def deconstruct_keys(keys) { parent: parent, operator: operator, name: name, location: location, comments: comments } end |
#format(q) ⇒ Object
5169 5170 5171 5172 5173 5174 5175 |
# File 'lib/syntax_tree/node.rb', line 5169 def format(q) q.group do q.format(parent) q.format(CallOperatorFormatter.new(operator), stackable: false) q.format(name) end end |
#pretty_print(q) ⇒ Object
5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 |
# File 'lib/syntax_tree/node.rb', line 5177 def pretty_print(q) q.group(2, "(", ")") do q.text("field") q.breakable q.pp(parent) q.breakable q.pp(operator) q.breakable q.pp(name) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 |
# File 'lib/syntax_tree/node.rb', line 5194 def to_json(*opts) { type: :field, parent: parent, op: operator, name: name, loc: location, cmts: comments }.to_json(*opts) end |