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
Constructor Details
#initialize(target:, operator:, value:, location:, comments: []) ⇒ OpAssign
Returns a new instance of OpAssign.
6391 6392 6393 6394 6395 6396 6397 |
# File 'lib/syntax_tree/node.rb', line 6391 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
6389 6390 6391 |
# File 'lib/syntax_tree/node.rb', line 6389 def comments @comments end |
#operator ⇒ Object (readonly)
- Op
-
the operator being used for the assignment
6383 6384 6385 |
# File 'lib/syntax_tree/node.rb', line 6383 def operator @operator end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
6380 6381 6382 |
# File 'lib/syntax_tree/node.rb', line 6380 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
6386 6387 6388 |
# File 'lib/syntax_tree/node.rb', line 6386 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
6399 6400 6401 |
# File 'lib/syntax_tree/node.rb', line 6399 def accept(visitor) visitor.visit_opassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6403 6404 6405 |
# File 'lib/syntax_tree/node.rb', line 6403 def child_nodes [target, operator, value] end |
#deconstruct_keys(keys) ⇒ Object
6409 6410 6411 6412 6413 6414 6415 6416 6417 |
# File 'lib/syntax_tree/node.rb', line 6409 def deconstruct_keys(keys) { target: target, operator: operator, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 |
# File 'lib/syntax_tree/node.rb', line 6419 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 |