class SyntaxTree::RAssign

RAssign represents a single-line pattern match.

value in pattern
value => pattern

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

operator[R]
Kw | Op

the operator being used to match against the pattern, which is

either => or in

pattern[R]
Node

the pattern on the right-hand side of the expression

value[R]
Node

the left-hand expression

Public Class Methods

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

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 3277
def ===(other)
  other.is_a?(RAssign) && value === other.value &&
    operator === other.operator && pattern === other.pattern
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 3223
def accept(visitor)
  visitor.visit_rassign(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 3227
def child_nodes
  [value, operator, pattern]
end
Also aliased as: deconstruct
copy(value: nil, operator: nil, pattern: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 3231
def copy(value: nil, operator: nil, pattern: nil, location: nil)
  node =
    RAssign.new(
      value: value || self.value,
      operator: operator || self.operator,
      pattern: pattern || self.pattern,
      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 3246
def deconstruct_keys(_keys)
  {
    value: value,
    operator: operator,
    pattern: pattern,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 3256
def format(q)
  q.group do
    q.format(value)
    q.text(" ")
    q.format(operator)

    case pattern
    when AryPtn, FndPtn, HshPtn
      q.text(" ")
      q.format(pattern)
    else
      q.group do
        q.indent do
          q.breakable_space
          q.format(pattern)
        end
      end
    end
  end
end