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.
5849 5850 5851 5852 5853 5854 5855 |
# File 'lib/syntax_tree/node.rb', line 5849 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
5847 5848 5849 |
# File 'lib/syntax_tree/node.rb', line 5847 def comments @comments end |
#operator ⇒ Object (readonly)
- Op
-
the operator being used for the assignment
5841 5842 5843 |
# File 'lib/syntax_tree/node.rb', line 5841 def operator @operator end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
5838 5839 5840 |
# File 'lib/syntax_tree/node.rb', line 5838 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
5844 5845 5846 |
# File 'lib/syntax_tree/node.rb', line 5844 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
5857 5858 5859 |
# File 'lib/syntax_tree/node.rb', line 5857 def accept(visitor) visitor.visit_opassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5861 5862 5863 |
# File 'lib/syntax_tree/node.rb', line 5861 def child_nodes [target, operator, value] end |
#deconstruct_keys(keys) ⇒ Object
5867 5868 5869 5870 5871 5872 5873 5874 5875 |
# File 'lib/syntax_tree/node.rb', line 5867 def deconstruct_keys(keys) { target: target, operator: operator, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 |
# File 'lib/syntax_tree/node.rb', line 5877 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 |