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, #pretty_print, #to_json
Constructor Details
#initialize(params:, locals:, location:) ⇒ LambdaVar
Returns a new instance of LambdaVar.
7162 7163 7164 7165 7166 7167 |
# File 'lib/syntax_tree/node.rb', line 7162 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
7160 7161 7162 |
# File 'lib/syntax_tree/node.rb', line 7160 def comments @comments end |
#locals ⇒ Object (readonly)
- Array[ Ident ]
-
the list of block-local variable declarations
7157 7158 7159 |
# File 'lib/syntax_tree/node.rb', line 7157 def locals @locals end |
#params ⇒ Object (readonly)
- Params
-
the parameters being declared with the block
7154 7155 7156 |
# File 'lib/syntax_tree/node.rb', line 7154 def params @params end |
Instance Method Details
#===(other) ⇒ Object
7208 7209 7210 7211 |
# File 'lib/syntax_tree/node.rb', line 7208 def ===(other) other.is_a?(LambdaVar) && params === other.params && ArrayMatch.call(locals, other.locals) end |
#accept(visitor) ⇒ Object
7169 7170 7171 |
# File 'lib/syntax_tree/node.rb', line 7169 def accept(visitor) visitor.visit_lambda_var(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7173 7174 7175 |
# File 'lib/syntax_tree/node.rb', line 7173 def child_nodes [params, *locals] end |
#copy(params: nil, locals: nil, location: nil) ⇒ Object
7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 |
# File 'lib/syntax_tree/node.rb', line 7177 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
7191 7192 7193 |
# File 'lib/syntax_tree/node.rb', line 7191 def deconstruct_keys(_keys) { params: params, locals: locals, location: location, comments: comments } end |
#empty? ⇒ Boolean
7195 7196 7197 |
# File 'lib/syntax_tree/node.rb', line 7195 def empty? params.empty? && locals.empty? end |