class SyntaxTree::OpAssign
variable += value
operator like += or ||=.
OpAssign represents assigning a value to a variable or constant using an
def ===(other)
def ===(other) other.is_a?(OpAssign) && target === other.target && operator === other.operator && value === other.value end
def accept(visitor)
def accept(visitor) visitor.visit_opassign(self) end
def child_nodes
def child_nodes [target, operator, value] end
def copy(target: nil, operator: nil, value: nil, location: nil)
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
def deconstruct_keys(_keys)
def deconstruct_keys(_keys) { target: target, operator: operator, value: value, location: location, comments: comments } end
def format(q)
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
def initialize(target:, operator:, value:, location:)
def initialize(target:, operator:, value:, location:) @target = target @operator = operator @value = value @location = location @comments = [] end
def skip_indent?
def skip_indent? target.comments.empty? && (target.is_a?(ARefField) || AssignFormatting.skip_indent?(value)) end