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.
6660 6661 6662 6663 6664 6665 6666 |
# File 'lib/syntax_tree/node.rb', line 6660 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
6658 6659 6660 |
# File 'lib/syntax_tree/node.rb', line 6658 def comments @comments end |
#operator ⇒ Object (readonly)
- Op
-
the operator being used for the assignment
6652 6653 6654 |
# File 'lib/syntax_tree/node.rb', line 6652 def operator @operator end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
6649 6650 6651 |
# File 'lib/syntax_tree/node.rb', line 6649 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
6655 6656 6657 |
# File 'lib/syntax_tree/node.rb', line 6655 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
6668 6669 6670 |
# File 'lib/syntax_tree/node.rb', line 6668 def accept(visitor) visitor.visit_opassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6672 6673 6674 |
# File 'lib/syntax_tree/node.rb', line 6672 def child_nodes [target, operator, value] end |
#deconstruct_keys(_keys) ⇒ Object
6678 6679 6680 6681 6682 6683 6684 6685 6686 |
# File 'lib/syntax_tree/node.rb', line 6678 def deconstruct_keys(_keys) { target: target, operator: operator, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 |
# File 'lib/syntax_tree/node.rb', line 6688 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 |