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.
8671 8672 8673 8674 8675 8676 8677 |
# File 'lib/syntax_tree.rb', line 8671 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
8669 8670 8671 |
# File 'lib/syntax_tree.rb', line 8669 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8666 8667 8668 |
# File 'lib/syntax_tree.rb', line 8666 def location @location end |
#operator ⇒ Object (readonly)
- Op
-
the operator being used for the assignment
8660 8661 8662 |
# File 'lib/syntax_tree.rb', line 8660 def operator @operator end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
8657 8658 8659 |
# File 'lib/syntax_tree.rb', line 8657 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
8663 8664 8665 |
# File 'lib/syntax_tree.rb', line 8663 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
8679 8680 8681 |
# File 'lib/syntax_tree.rb', line 8679 def child_nodes [target, operator, value] end |
#format(q) ⇒ Object
8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 |
# File 'lib/syntax_tree.rb', line 8683 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
8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 |
# File 'lib/syntax_tree.rb', line 8695 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
8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 |
# File 'lib/syntax_tree.rb', line 8712 def to_json(*opts) { type: :opassign, target: target, op: operator, value: value, loc: location, cmts: comments }.to_json(*opts) end |