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



6266
6267
6268
6269
6270
6271
# File 'lib/syntax_tree/node.rb', line 6266

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



6264
6265
6266
# File 'lib/syntax_tree/node.rb', line 6264

def comments
  @comments
end

#localsObject (readonly)

Array[ Ident ]

the list of block-local variable declarations



6261
6262
6263
# File 'lib/syntax_tree/node.rb', line 6261

def locals
  @locals
end

#paramsObject (readonly)

Params

the parameters being declared with the block



6258
6259
6260
# File 'lib/syntax_tree/node.rb', line 6258

def params
  @params
end

Instance Method Details

#accept(visitor) ⇒ Object



6273
6274
6275
# File 'lib/syntax_tree/node.rb', line 6273

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

#child_nodesObject Also known as: deconstruct



6277
6278
6279
# File 'lib/syntax_tree/node.rb', line 6277

def child_nodes
  [params, *locals]
end

#deconstruct_keys(_keys) ⇒ Object



6283
6284
6285
# File 'lib/syntax_tree/node.rb', line 6283

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

#empty?Boolean



6287
6288
6289
# File 'lib/syntax_tree/node.rb', line 6287

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

#format(q) ⇒ Object



6291
6292
6293
6294
6295
6296
6297
6298
# File 'lib/syntax_tree/node.rb', line 6291

def format(q)
  q.format(params)

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