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
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(params:, locals:, location:, comments: []) ⇒ BlockVar
constructor
A new instance of BlockVar.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(params:, locals:, location:, comments: []) ⇒ BlockVar
Returns a new instance of BlockVar.
2007 2008 2009 2010 2011 2012 |
# File 'lib/syntax_tree/node.rb', line 2007 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
2005 2006 2007 |
# File 'lib/syntax_tree/node.rb', line 2005 def comments @comments end |
#locals ⇒ Object (readonly)
- Array[ Ident ]
-
the list of block-local variable declarations
2002 2003 2004 |
# File 'lib/syntax_tree/node.rb', line 2002 def locals @locals end |
#params ⇒ Object (readonly)
- Params
-
the parameters being declared with the block
1999 2000 2001 |
# File 'lib/syntax_tree/node.rb', line 1999 def params @params end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
2014 2015 2016 |
# File 'lib/syntax_tree/node.rb', line 2014 def child_nodes [params, *locals] end |
#deconstruct_keys(keys) ⇒ Object
2020 2021 2022 |
# File 'lib/syntax_tree/node.rb', line 2020 def deconstruct_keys(keys) { params: params, locals: locals, location: location, comments: comments } end |
#format(q) ⇒ Object
2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 |
# File 'lib/syntax_tree/node.rb', line 2024 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 |
#pretty_print(q) ⇒ Object
2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 |
# File 'lib/syntax_tree/node.rb', line 2036 def pretty_print(q) q.group(2, "(", ")") do q.text("block_var") q.breakable q.pp(params) if locals.any? q.breakable q.group(2, "(", ")") { q.seplist(locals) { |local| q.pp(local) } } end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
2052 2053 2054 2055 2056 2057 2058 2059 2060 |
# File 'lib/syntax_tree/node.rb', line 2052 def to_json(*opts) { type: :block_var, params: params, locals: locals, loc: location, cmts: comments }.to_json(*opts) end |