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.
8068 8069 8070 8071 8072 8073 8074 |
# File 'lib/syntax_tree/node.rb', line 8068 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
8066 8067 8068 |
# File 'lib/syntax_tree/node.rb', line 8066 def comments @comments end |
#operator ⇒ Object (readonly)
- Op
-
the operator being used for the assignment
8060 8061 8062 |
# File 'lib/syntax_tree/node.rb', line 8060 def operator @operator end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
8057 8058 8059 |
# File 'lib/syntax_tree/node.rb', line 8057 def target @target end |
#value ⇒ Object (readonly)
- Node
-
the expression to be assigned
8063 8064 8065 |
# File 'lib/syntax_tree/node.rb', line 8063 def value @value end |
Instance Method Details
#===(other) ⇒ Object
8127 8128 8129 8130 |
# File 'lib/syntax_tree/node.rb', line 8127 def ===(other) other.is_a?(OpAssign) && target === other.target && operator === other.operator && value === other.value end |
#accept(visitor) ⇒ Object
8076 8077 8078 |
# File 'lib/syntax_tree/node.rb', line 8076 def accept(visitor) visitor.visit_opassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8080 8081 8082 |
# File 'lib/syntax_tree/node.rb', line 8080 def child_nodes [target, operator, value] end |
#copy(target: nil, operator: nil, value: nil, location: nil) ⇒ Object
8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 |
# File 'lib/syntax_tree/node.rb', line 8084 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
8099 8100 8101 8102 8103 8104 8105 8106 8107 |
# File 'lib/syntax_tree/node.rb', line 8099 def deconstruct_keys(_keys) { target: target, operator: operator, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 |
# File 'lib/syntax_tree/node.rb', line 8109 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 |