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.



6082
6083
6084
6085
6086
6087
# File 'lib/syntax_tree/node.rb', line 6082

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



6080
6081
6082
# File 'lib/syntax_tree/node.rb', line 6080

def comments
  @comments
end

#localsObject (readonly)

Array[ Ident ]

the list of block-local variable declarations



6077
6078
6079
# File 'lib/syntax_tree/node.rb', line 6077

def locals
  @locals
end

#paramsObject (readonly)

Params

the parameters being declared with the block



6074
6075
6076
# File 'lib/syntax_tree/node.rb', line 6074

def params
  @params
end

Instance Method Details

#accept(visitor) ⇒ Object



6089
6090
6091
# File 'lib/syntax_tree/node.rb', line 6089

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

#child_nodesObject Also known as: deconstruct



6093
6094
6095
# File 'lib/syntax_tree/node.rb', line 6093

def child_nodes
  [params, *locals]
end

#deconstruct_keys(_keys) ⇒ Object



6099
6100
6101
# File 'lib/syntax_tree/node.rb', line 6099

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

#empty?Boolean

Returns:

  • (Boolean)


6103
6104
6105
# File 'lib/syntax_tree/node.rb', line 6103

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

#format(q) ⇒ Object



6107
6108
6109
6110
6111
6112
6113
6114
# File 'lib/syntax_tree/node.rb', line 6107

def format(q)
  q.format(params)

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