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.



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

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

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



6027
6028
6029
# File 'lib/syntax_tree/node.rb', line 6027

def comments
  @comments
end

#locals ⇒ Object (readonly)

[Array[ Ident ]] the list of block-local variable declarations



6024
6025
6026
# File 'lib/syntax_tree/node.rb', line 6024

def locals
  @locals
end

#params ⇒ Object (readonly)

[Params] the parameters being declared with the block



6021
6022
6023
# File 'lib/syntax_tree/node.rb', line 6021

def params
  @params
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodes ⇒ Object Also known as: deconstruct



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

def child_nodes
  [params, *locals]
end

#deconstruct_keys(_keys) ⇒ Object



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

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

#empty? ⇒ Boolean

Returns:

  • (Boolean)


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

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

#format(q) ⇒ Object



6054
6055
6056
6057
6058
6059
6060
6061
# File 'lib/syntax_tree/node.rb', line 6054

def format(q)
  q.format(params)

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