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.
6096 6097 6098 6099 6100 6101 |
# File 'lib/syntax_tree/node.rb', line 6096 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
6094 6095 6096 |
# File 'lib/syntax_tree/node.rb', line 6094 def comments @comments end |
#locals ⇒ Object (readonly)
- Array[ Ident ]
-
the list of block-local variable declarations
6091 6092 6093 |
# File 'lib/syntax_tree/node.rb', line 6091 def locals @locals end |
#params ⇒ Object (readonly)
- Params
-
the parameters being declared with the block
6088 6089 6090 |
# File 'lib/syntax_tree/node.rb', line 6088 def params @params end |
Instance Method Details
#accept(visitor) ⇒ Object
6103 6104 6105 |
# File 'lib/syntax_tree/node.rb', line 6103 def accept(visitor) visitor.visit_lambda_var(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6107 6108 6109 |
# File 'lib/syntax_tree/node.rb', line 6107 def child_nodes [params, *locals] end |
#deconstruct_keys(_keys) ⇒ Object
6113 6114 6115 |
# File 'lib/syntax_tree/node.rb', line 6113 def deconstruct_keys(_keys) { params: params, locals: locals, location: location, comments: comments } end |
#empty? ⇒ Boolean
6117 6118 6119 |
# File 'lib/syntax_tree/node.rb', line 6117 def empty? params.empty? && locals.empty? end |
#format(q) ⇒ Object
6121 6122 6123 6124 6125 6126 6127 6128 |
# File 'lib/syntax_tree/node.rb', line 6121 def format(q) q.format(params) if locals.any? q.text("; ") q.seplist(locals, -> { q.text(", ") }) { |local| q.format(local) } end end |