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
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #empty? ⇒ Boolean
- #format(q) ⇒ Object
-
#initialize(params:, locals:, location:, comments: []) ⇒ LambdaVar
constructor
A new instance of LambdaVar.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(params:, locals:, location:, comments: []) ⇒ LambdaVar
Returns a new instance of LambdaVar.
6040 6041 6042 6043 6044 6045 |
# File 'lib/syntax_tree/node.rb', line 6040 def initialize(params:, locals:, location:, comments: []) @params = params @locals = locals @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6038 6039 6040 |
# File 'lib/syntax_tree/node.rb', line 6038 def comments @comments end |
#locals ⇒ Object (readonly)
- Array[ Ident ]
-
the list of block-local variable declarations
6035 6036 6037 |
# File 'lib/syntax_tree/node.rb', line 6035 def locals @locals end |
#params ⇒ Object (readonly)
- Params
-
the parameters being declared with the block
6032 6033 6034 |
# File 'lib/syntax_tree/node.rb', line 6032 def params @params end |
Instance Method Details
#accept(visitor) ⇒ Object
6047 6048 6049 |
# File 'lib/syntax_tree/node.rb', line 6047 def accept(visitor) visitor.visit_lambda_var(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6051 6052 6053 |
# File 'lib/syntax_tree/node.rb', line 6051 def child_nodes [params, *locals] end |
#deconstruct_keys(_keys) ⇒ Object
6057 6058 6059 |
# File 'lib/syntax_tree/node.rb', line 6057 def deconstruct_keys(_keys) { params: params, locals: locals, location: location, comments: comments } end |
#empty? ⇒ Boolean
6061 6062 6063 |
# File 'lib/syntax_tree/node.rb', line 6061 def empty? params.empty? && locals.empty? end |
#format(q) ⇒ Object
6065 6066 6067 6068 6069 6070 6071 6072 |
# File 'lib/syntax_tree/node.rb', line 6065 def format(q) q.format(params) if locals.any? q.text("; ") q.seplist(locals, -> { q.text(", ") }) { |local| q.format(local) } end end |