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.
6561 6562 6563 6564 6565 6566 6567 |
# File 'lib/syntax_tree/node.rb', line 6561 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
6559 6560 6561 |
# File 'lib/syntax_tree/node.rb', line 6559 def comments @comments end |
#operator ⇒ Object (readonly)
- Op
-
the operator being used for the assignment
6553 6554 6555 |
# File 'lib/syntax_tree/node.rb', line 6553 def operator @operator end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
6550 6551 6552 |
# File 'lib/syntax_tree/node.rb', line 6550 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
6556 6557 6558 |
# File 'lib/syntax_tree/node.rb', line 6556 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
6569 6570 6571 |
# File 'lib/syntax_tree/node.rb', line 6569 def accept(visitor) visitor.visit_opassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6573 6574 6575 |
# File 'lib/syntax_tree/node.rb', line 6573 def child_nodes [target, operator, value] end |
#deconstruct_keys(_keys) ⇒ Object
6579 6580 6581 6582 6583 6584 6585 6586 6587 |
# File 'lib/syntax_tree/node.rb', line 6579 def deconstruct_keys(_keys) { target: target, operator: operator, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 |
# File 'lib/syntax_tree/node.rb', line 6589 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 |