class SyntaxTree::OpAssign

OpAssign represents assigning a value to a variable or constant using an operator like += or ||=.

variable += value

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

operator[R]
Op

the operator being used for the assignment

target[R]
ARefField | ConstPathField | Field | TopConstField | VarField

the target

to assign the result of the expression to

value[R]
Node

the expression to be assigned

Public Class Methods

new(target:, operator:, value:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 8052
def initialize(target:, operator:, value:, location:)
  @target = target
  @operator = operator
  @value = value
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# 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) click to toggle source
# File lib/syntax_tree/node.rb, line 8060
def accept(visitor)
  visitor.visit_opassign(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 8064
def child_nodes
  [target, operator, value]
end
Also aliased as: deconstruct
copy(target: nil, operator: nil, value: nil, location: nil) click to toggle source
# 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()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# 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) click to toggle source
# 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