Class: SyntaxTree::OpAssign
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.
-
#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.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, operator:, value:, location:, comments: []) ⇒ OpAssign
constructor
A new instance of OpAssign.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(target:, operator:, value:, location:, comments: []) ⇒ OpAssign
Returns a new instance of OpAssign.
6482 6483 6484 6485 6486 6487 6488 |
# File 'lib/syntax_tree/node.rb', line 6482 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
6480 6481 6482 |
# File 'lib/syntax_tree/node.rb', line 6480 def comments @comments end |
#operator ⇒ Object (readonly)
- Op
-
the operator being used for the assignment
6474 6475 6476 |
# File 'lib/syntax_tree/node.rb', line 6474 def operator @operator end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
6471 6472 6473 |
# File 'lib/syntax_tree/node.rb', line 6471 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
6477 6478 6479 |
# File 'lib/syntax_tree/node.rb', line 6477 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
6490 6491 6492 |
# File 'lib/syntax_tree/node.rb', line 6490 def accept(visitor) visitor.visit_opassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6494 6495 6496 |
# File 'lib/syntax_tree/node.rb', line 6494 def child_nodes [target, operator, value] end |
#deconstruct_keys(_keys) ⇒ Object
6500 6501 6502 6503 6504 6505 6506 6507 6508 |
# File 'lib/syntax_tree/node.rb', line 6500 def deconstruct_keys(_keys) { target: target, operator: operator, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 |
# File 'lib/syntax_tree/node.rb', line 6510 def format(q) q.group do q.format(target) q.text(" ") q.format(operator) if skip_indent? q.text(" ") q.format(value) else q.indent do q.breakable q.format(value) end end end end |