Class: SyntaxTree::BlockArg
- Inherits:
-
Object
- Object
- SyntaxTree::BlockArg
- Defined in:
- lib/syntax_tree.rb
Overview
BlockArg represents declaring a block parameter on a method definition.
def method(&block); end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#name ⇒ Object
readonly
- Ident
-
the name of the block argument.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(name:, location:, comments: []) ⇒ BlockArg
constructor
A new instance of BlockArg.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(name:, location:, comments: []) ⇒ BlockArg
Returns a new instance of BlockArg.
2573 2574 2575 2576 2577 |
# File 'lib/syntax_tree.rb', line 2573 def initialize(name:, location:, comments: []) @name = name @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2571 2572 2573 |
# File 'lib/syntax_tree.rb', line 2571 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
2568 2569 2570 |
# File 'lib/syntax_tree.rb', line 2568 def location @location end |
#name ⇒ Object (readonly)
- Ident
-
the name of the block argument
2565 2566 2567 |
# File 'lib/syntax_tree.rb', line 2565 def name @name end |
Instance Method Details
#child_nodes ⇒ Object
2579 2580 2581 |
# File 'lib/syntax_tree.rb', line 2579 def child_nodes [name] end |
#format(q) ⇒ Object
2583 2584 2585 2586 |
# File 'lib/syntax_tree.rb', line 2583 def format(q) q.text("&") q.format(name) end |
#pretty_print(q) ⇒ Object
2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 |
# File 'lib/syntax_tree.rb', line 2588 def pretty_print(q) q.group(2, "(", ")") do q.text("blockarg") q.breakable q.pp(name) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
2599 2600 2601 2602 2603 |
# File 'lib/syntax_tree.rb', line 2599 def to_json(*opts) { type: :blockarg, name: name, loc: location, cmts: comments }.to_json( *opts ) end |