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.
8011 8012 8013 8014 8015 8016 8017 |
# File 'lib/syntax_tree/node.rb', line 8011 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
8009 8010 8011 |
# File 'lib/syntax_tree/node.rb', line 8009 def comments @comments end |
#operator ⇒ Object (readonly)
- Op
-
the operator being used for the assignment
8003 8004 8005 |
# File 'lib/syntax_tree/node.rb', line 8003 def operator @operator end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
8000 8001 8002 |
# File 'lib/syntax_tree/node.rb', line 8000 def target @target end |
#value ⇒ Object (readonly)
- Node
-
the expression to be assigned
8006 8007 8008 |
# File 'lib/syntax_tree/node.rb', line 8006 def value @value end |
Instance Method Details
#===(other) ⇒ Object
8070 8071 8072 8073 |
# File 'lib/syntax_tree/node.rb', line 8070 def ===(other) other.is_a?(OpAssign) && target === other.target && operator === other.operator && value === other.value end |
#accept(visitor) ⇒ Object
8019 8020 8021 |
# File 'lib/syntax_tree/node.rb', line 8019 def accept(visitor) visitor.visit_opassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8023 8024 8025 |
# File 'lib/syntax_tree/node.rb', line 8023 def child_nodes [target, operator, value] end |
#copy(target: nil, operator: nil, value: nil, location: nil) ⇒ Object
8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 |
# File 'lib/syntax_tree/node.rb', line 8027 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
8042 8043 8044 8045 8046 8047 8048 8049 8050 |
# File 'lib/syntax_tree/node.rb', line 8042 def deconstruct_keys(_keys) { target: target, operator: operator, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 |
# File 'lib/syntax_tree/node.rb', line 8052 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 |