Class: SyntaxTree::LambdaVar
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::LambdaVar
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
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#locals ⇒ Object
readonly
- Array[ Ident ]
-
the list of block-local variable declarations.
-
#params ⇒ Object
readonly
- Params
-
the parameters being declared with the block.
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(params:, locals:, location:) ⇒ LambdaVar
Returns a new instance of LambdaVar.
7222
7223
7224
7225
7226
7227
|
# File 'lib/syntax_tree/node.rb', line 7222
def initialize(params:, locals:, location:)
@params = params
@locals = locals
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7220
7221
7222
|
# File 'lib/syntax_tree/node.rb', line 7220
def
end
|
#locals ⇒ Object
- Array[ Ident ]
-
the list of block-local variable declarations
7217
7218
7219
|
# File 'lib/syntax_tree/node.rb', line 7217
def locals
@locals
end
|
#params ⇒ Object
- Params
-
the parameters being declared with the block
7214
7215
7216
|
# File 'lib/syntax_tree/node.rb', line 7214
def params
@params
end
|
Instance Method Details
#===(other) ⇒ Object
7268
7269
7270
7271
|
# File 'lib/syntax_tree/node.rb', line 7268
def ===(other)
other.is_a?(LambdaVar) && params === other.params &&
ArrayMatch.call(locals, other.locals)
end
|
#accept(visitor) ⇒ Object
7229
7230
7231
|
# File 'lib/syntax_tree/node.rb', line 7229
def accept(visitor)
visitor.visit_lambda_var(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7233
7234
7235
|
# File 'lib/syntax_tree/node.rb', line 7233
def child_nodes
[params, *locals]
end
|
#copy(params: nil, locals: nil, location: nil) ⇒ Object
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
|
# File 'lib/syntax_tree/node.rb', line 7237
def copy(params: nil, locals: nil, location: nil)
node =
LambdaVar.new(
params: params || self.params,
locals: locals || self.locals,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
7251
7252
7253
|
# File 'lib/syntax_tree/node.rb', line 7251
def deconstruct_keys(_keys)
{ params: params, locals: locals, location: location, comments: }
end
|
#empty? ⇒ Boolean
7255
7256
7257
|
# File 'lib/syntax_tree/node.rb', line 7255
def empty?
params.empty? && locals.empty?
end
|
7259
7260
7261
7262
7263
7264
7265
7266
|
# File 'lib/syntax_tree/node.rb', line 7259
def format(q)
q.format(params)
if locals.any?
q.text("; ")
q.seplist(locals, BlockVar::SEPARATOR) { |local| q.format(local) }
end
end
|