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, #pretty_print, #to_json
Constructor Details
#initialize(params:, locals:, location:) ⇒ LambdaVar
Returns a new instance of LambdaVar.
7150
7151
7152
7153
7154
7155
|
# File 'lib/syntax_tree/node.rb', line 7150
def initialize(params:, locals:, location:)
@params = params
@locals = locals
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7148
7149
7150
|
# File 'lib/syntax_tree/node.rb', line 7148
def
end
|
#locals ⇒ Object
- Array[ Ident ]
-
the list of block-local variable declarations
7145
7146
7147
|
# File 'lib/syntax_tree/node.rb', line 7145
def locals
@locals
end
|
#params ⇒ Object
- Params
-
the parameters being declared with the block
7142
7143
7144
|
# File 'lib/syntax_tree/node.rb', line 7142
def params
@params
end
|
Instance Method Details
#===(other) ⇒ Object
7196
7197
7198
7199
|
# File 'lib/syntax_tree/node.rb', line 7196
def ===(other)
other.is_a?(LambdaVar) && params === other.params &&
ArrayMatch.call(locals, other.locals)
end
|
#accept(visitor) ⇒ Object
7157
7158
7159
|
# File 'lib/syntax_tree/node.rb', line 7157
def accept(visitor)
visitor.visit_lambda_var(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7161
7162
7163
|
# File 'lib/syntax_tree/node.rb', line 7161
def child_nodes
[params, *locals]
end
|
#copy(params: nil, locals: nil, location: nil) ⇒ Object
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
|
# File 'lib/syntax_tree/node.rb', line 7165
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
7179
7180
7181
|
# File 'lib/syntax_tree/node.rb', line 7179
def deconstruct_keys(_keys)
{ params: params, locals: locals, location: location, comments: }
end
|
#empty? ⇒ Boolean
7183
7184
7185
|
# File 'lib/syntax_tree/node.rb', line 7183
def empty?
params.empty? && locals.empty?
end
|
7187
7188
7189
7190
7191
7192
7193
7194
|
# File 'lib/syntax_tree/node.rb', line 7187
def format(q)
q.format(params)
if locals.any?
q.text("; ")
q.seplist(locals, BlockVar::SEPARATOR) { |local| q.format(local) }
end
end
|