Class: SyntaxTree::LambdaVar

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(params:, locals:, location:, comments: []) ⇒ LambdaVar

Returns a new instance of LambdaVar.



6040
6041
6042
6043
6044
6045
# File 'lib/syntax_tree/node.rb', line 6040

def initialize(params:, locals:, location:, comments: [])
  @params = params
  @locals = locals
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6038
6039
6040
# File 'lib/syntax_tree/node.rb', line 6038

def comments
  @comments
end

#localsObject (readonly)

Array[ Ident ]

the list of block-local variable declarations



6035
6036
6037
# File 'lib/syntax_tree/node.rb', line 6035

def locals
  @locals
end

#paramsObject (readonly)

Params

the parameters being declared with the block



6032
6033
6034
# File 'lib/syntax_tree/node.rb', line 6032

def params
  @params
end

Instance Method Details

#accept(visitor) ⇒ Object



6047
6048
6049
# File 'lib/syntax_tree/node.rb', line 6047

def accept(visitor)
  visitor.visit_lambda_var(self)
end

#child_nodesObject Also known as: deconstruct



6051
6052
6053
# File 'lib/syntax_tree/node.rb', line 6051

def child_nodes
  [params, *locals]
end

#deconstruct_keys(_keys) ⇒ Object



6057
6058
6059
# File 'lib/syntax_tree/node.rb', line 6057

def deconstruct_keys(_keys)
  { params: params, locals: locals, location: location, comments: comments }
end

#empty?Boolean

Returns:

  • (Boolean)


6061
6062
6063
# File 'lib/syntax_tree/node.rb', line 6061

def empty?
  params.empty? && locals.empty?
end

#format(q) ⇒ Object



6065
6066
6067
6068
6069
6070
6071
6072
# File 'lib/syntax_tree/node.rb', line 6065

def format(q)
  q.format(params)

  if locals.any?
    q.text("; ")
    q.seplist(locals, -> { q.text(", ") }) { |local| q.format(local) }
  end
end