Class: SyntaxTree::BlockVar
Overview
BlockVar represents the parameters being declared for a block. Effectively this node is everything contained within the pipes. This includes all of the various parameter types, as well as block-local variable declarations.
method do |positional, optional = value, keyword:, █ local|
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
- #format(q) ⇒ Object
-
#initialize(params:, locals:, location:, comments: []) ⇒ BlockVar
constructor
A new instance of BlockVar.
Methods inherited from Node
Constructor Details
#initialize(params:, locals:, location:, comments: []) ⇒ BlockVar
Returns a new instance of BlockVar.
1668 1669 1670 1671 1672 1673 |
# File 'lib/syntax_tree/node.rb', line 1668 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
1666 1667 1668 |
# File 'lib/syntax_tree/node.rb', line 1666 def comments @comments end |
#locals ⇒ Object (readonly)
- Array[ Ident ]
-
the list of block-local variable declarations
1663 1664 1665 |
# File 'lib/syntax_tree/node.rb', line 1663 def locals @locals end |
#params ⇒ Object (readonly)
- Params
-
the parameters being declared with the block
1660 1661 1662 |
# File 'lib/syntax_tree/node.rb', line 1660 def params @params end |
Instance Method Details
#accept(visitor) ⇒ Object
1675 1676 1677 |
# File 'lib/syntax_tree/node.rb', line 1675 def accept(visitor) visitor.visit_block_var(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
1679 1680 1681 |
# File 'lib/syntax_tree/node.rb', line 1679 def child_nodes [params, *locals] end |
#deconstruct_keys(keys) ⇒ Object
1685 1686 1687 |
# File 'lib/syntax_tree/node.rb', line 1685 def deconstruct_keys(keys) { params: params, locals: locals, location: location, comments: comments } end |
#format(q) ⇒ Object
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 |
# File 'lib/syntax_tree/node.rb', line 1689 def format(q) q.group(0, "|", "|") do doc = q.format(params) RemoveBreaks.call(doc) if locals.any? q.text("; ") q.seplist(locals, -> { q.text(", ") }) { |local| q.format(local) } end end end |