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
- Node
-
the expression to be assigned.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(target: nil, operator: nil, value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, operator:, value:, location:) ⇒ OpAssign
constructor
A new instance of OpAssign.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(target:, operator:, value:, location:) ⇒ OpAssign
Returns a new instance of OpAssign.
8052 8053 8054 8055 8056 8057 8058 |
# File 'lib/syntax_tree/node.rb', line 8052 def initialize(target:, operator:, value:, location:) @target = target @operator = operator @value = value @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8050 8051 8052 |
# File 'lib/syntax_tree/node.rb', line 8050 def comments @comments end |
#operator ⇒ Object (readonly)
- Op
-
the operator being used for the assignment
8044 8045 8046 |
# File 'lib/syntax_tree/node.rb', line 8044 def operator @operator end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
8041 8042 8043 |
# File 'lib/syntax_tree/node.rb', line 8041 def target @target end |
#value ⇒ Object (readonly)
- Node
-
the expression to be assigned
8047 8048 8049 |
# File 'lib/syntax_tree/node.rb', line 8047 def value @value end |
Instance Method Details
#===(other) ⇒ Object
8111 8112 8113 8114 |
# File 'lib/syntax_tree/node.rb', line 8111 def ===(other) other.is_a?(OpAssign) && target === other.target && operator === other.operator && value === other.value end |
#accept(visitor) ⇒ Object
8060 8061 8062 |
# File 'lib/syntax_tree/node.rb', line 8060 def accept(visitor) visitor.visit_opassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8064 8065 8066 |
# File 'lib/syntax_tree/node.rb', line 8064 def child_nodes [target, operator, value] end |
#copy(target: nil, operator: nil, value: nil, location: nil) ⇒ Object
8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 |
# File 'lib/syntax_tree/node.rb', line 8068 def copy(target: nil, operator: nil, value: nil, location: nil) node = OpAssign.new( target: target || self.target, operator: operator || self.operator, value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
8083 8084 8085 8086 8087 8088 8089 8090 8091 |
# File 'lib/syntax_tree/node.rb', line 8083 def deconstruct_keys(_keys) { target: target, operator: operator, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 |
# File 'lib/syntax_tree/node.rb', line 8093 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_space q.format(value) end end end end |