class SyntaxTree::Assign

Assign represents assigning something to a variable or constant. Generally, the left side of the assignment is going to be any node that ends with the name “Field”.

variable = value

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

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:, value:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 1429
def initialize(target:, value:, location:)
  @target = target
  @value = value
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 1479
def ===(other)
  other.is_a?(Assign) && target === other.target && value === other.value
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 1436
def accept(visitor)
  visitor.visit_assign(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 1440
def child_nodes
  [target, value]
end
Also aliased as: deconstruct
copy(target: nil, value: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 1444
def copy(target: nil, value: nil, location: nil)
  node =
    Assign.new(
      target: target || self.target,
      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 1458
def deconstruct_keys(_keys)
  { target: target, value: value, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 1462
def format(q)
  q.group do
    q.format(target)
    q.text(" =")

    if skip_indent?
      q.text(" ")
      q.format(value)
    else
      q.indent do
        q.breakable_space
        q.format(value)
      end
    end
  end
end