Class: SyntaxTree::OpAssign
- Inherits:
-
Object
- Object
- SyntaxTree::OpAssign
- Defined in:
- lib/syntax_tree.rb
Overview
OpAssign represents assigning a value to a variable or constant using an operator like += or ||=.
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.
-
#operator ⇒ Object
readonly
- Op
-
the operator being used for the assignment.
-
#target ⇒ Object
readonly
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target to assign the result of the expression to.
-
#value ⇒ Object
readonly
- untyped
-
the expression to be assigned.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, operator:, value:, location:, comments: []) ⇒ OpAssign
constructor
A new instance of OpAssign.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(target:, operator:, value:, location:, comments: []) ⇒ OpAssign
Returns a new instance of OpAssign.
8335 8336 8337 8338 8339 8340 8341 |
# File 'lib/syntax_tree.rb', line 8335 def initialize(target:, operator:, value:, location:, comments: []) @target = target @operator = operator @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8333 8334 8335 |
# File 'lib/syntax_tree.rb', line 8333 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8330 8331 8332 |
# File 'lib/syntax_tree.rb', line 8330 def location @location end |
#operator ⇒ Object (readonly)
- Op
-
the operator being used for the assignment
8324 8325 8326 |
# File 'lib/syntax_tree.rb', line 8324 def operator @operator end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
8321 8322 8323 |
# File 'lib/syntax_tree.rb', line 8321 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
8327 8328 8329 |
# File 'lib/syntax_tree.rb', line 8327 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
8343 8344 8345 |
# File 'lib/syntax_tree.rb', line 8343 def child_nodes [target, operator, value] end |
#format(q) ⇒ Object
8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 |
# File 'lib/syntax_tree.rb', line 8347 def format(q) q.group do q.format(target) q.text(" ") q.format(operator) q.indent do q.breakable q.format(value) end end end |
#pretty_print(q) ⇒ Object
8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 |
# File 'lib/syntax_tree.rb', line 8359 def pretty_print(q) q.group(2, "(", ")") do q.text("opassign") q.breakable q.pp(target) q.breakable q.pp(operator) q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 |
# File 'lib/syntax_tree.rb', line 8376 def to_json(*opts) { type: :opassign, target: target, op: operator, value: value, loc: location, cmts: comments }.to_json(*opts) end |