Class: SyntaxTree::LambdaVar
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
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(params: nil, locals: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #empty? ⇒ Boolean
- #format(q) ⇒ Object
-
#initialize(params:, locals:, location:) ⇒ LambdaVar
constructor
A new instance of LambdaVar.
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.
7263 7264 7265 7266 7267 7268 |
# File 'lib/syntax_tree/node.rb', line 7263 def initialize(params:, locals:, location:) @params = params @locals = locals @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7261 7262 7263 |
# File 'lib/syntax_tree/node.rb', line 7261 def comments @comments end |
#locals ⇒ Object (readonly)
- Array[ Ident ]
-
the list of block-local variable declarations
7258 7259 7260 |
# File 'lib/syntax_tree/node.rb', line 7258 def locals @locals end |
#params ⇒ Object (readonly)
- Params
-
the parameters being declared with the block
7255 7256 7257 |
# File 'lib/syntax_tree/node.rb', line 7255 def params @params end |
Instance Method Details
#===(other) ⇒ Object
7309 7310 7311 7312 |
# File 'lib/syntax_tree/node.rb', line 7309 def ===(other) other.is_a?(LambdaVar) && params === other.params && ArrayMatch.call(locals, other.locals) end |
#accept(visitor) ⇒ Object
7270 7271 7272 |
# File 'lib/syntax_tree/node.rb', line 7270 def accept(visitor) visitor.visit_lambda_var(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7274 7275 7276 |
# File 'lib/syntax_tree/node.rb', line 7274 def child_nodes [params, *locals] end |
#copy(params: nil, locals: nil, location: nil) ⇒ Object
7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 |
# File 'lib/syntax_tree/node.rb', line 7278 def copy(params: nil, locals: nil, location: nil) node = LambdaVar.new( params: params || self.params, locals: locals || self.locals, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
7292 7293 7294 |
# File 'lib/syntax_tree/node.rb', line 7292 def deconstruct_keys(_keys) { params: params, locals: locals, location: location, comments: comments } end |
#empty? ⇒ Boolean
7296 7297 7298 |
# File 'lib/syntax_tree/node.rb', line 7296 def empty? params.empty? && locals.empty? end |