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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(params:, locals:, location:, comments: []) ⇒ BlockVar
Returns a new instance of BlockVar.
1708 1709 1710 1711 1712 1713 |
# File 'lib/syntax_tree/node.rb', line 1708 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
1706 1707 1708 |
# File 'lib/syntax_tree/node.rb', line 1706 def comments @comments end |
#locals ⇒ Object (readonly)
[Array[ Ident ]] the list of block-local variable declarations
1703 1704 1705 |
# File 'lib/syntax_tree/node.rb', line 1703 def locals @locals end |
#params ⇒ Object (readonly)
[Params] the parameters being declared with the block
1700 1701 1702 |
# File 'lib/syntax_tree/node.rb', line 1700 def params @params end |
Instance Method Details
#accept(visitor) ⇒ Object
1715 1716 1717 |
# File 'lib/syntax_tree/node.rb', line 1715 def accept(visitor) visitor.visit_block_var(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
1719 1720 1721 |
# File 'lib/syntax_tree/node.rb', line 1719 def child_nodes [params, *locals] end |
#deconstruct_keys(_keys) ⇒ Object
1725 1726 1727 |
# File 'lib/syntax_tree/node.rb', line 1725 def deconstruct_keys(_keys) { params: params, locals: locals, location: location, comments: comments } end |
#format(q) ⇒ Object
1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 |
# File 'lib/syntax_tree/node.rb', line 1729 def format(q) q.group(0, "|", "|") do q.remove_breaks(q.format(params)) if locals.any? q.text("; ") q.seplist(locals, -> { q.text(", ") }) { |local| q.format(local) } end end end |