class SyntaxTree::LambdaVar

LambdaVar represents the parameters being declared for a lambda. Effectively this node is everything contained within the parentheses. This includes all of the various parameter types, as well as block-local variable declarations.

-> (positional, optional = value, keyword:, █ local) do
end

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

locals[R]
Array[ Ident ]

the list of block-local variable declarations

params[R]
Params

the parameters being declared with the block

Public Class Methods

new(params:, locals:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 7263
def initialize(params:, locals:, location:)
  @params = params
  @locals = locals
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 7309
def ===(other)
  other.is_a?(LambdaVar) && params === other.params &&
    ArrayMatch.call(locals, other.locals)
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 7270
def accept(visitor)
  visitor.visit_lambda_var(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 7274
def child_nodes
  [params, *locals]
end
Also aliased as: deconstruct
copy(params: nil, locals: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 7278
def copy(params: nil, locals: nil, location: nil)
  node =
    LambdaVar.new(
      params: params || self.params,
      locals: locals || self.locals,
      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 7292
def deconstruct_keys(_keys)
  { params: params, locals: locals, location: location, comments: comments }
end
empty?() click to toggle source
# File lib/syntax_tree/node.rb, line 7296
def empty?
  params.empty? && locals.empty?
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 7300
def format(q)
  q.format(params)

  if locals.any?
    q.text("; ")
    q.seplist(locals, BlockVar::SEPARATOR) { |local| q.format(local) }
  end
end