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
- nil | 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.
2706 2707 2708 2709 2710 |
# File 'lib/syntax_tree.rb', line 2706 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
2704 2705 2706 |
# File 'lib/syntax_tree.rb', line 2704 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
2701 2702 2703 |
# File 'lib/syntax_tree.rb', line 2701 def location @location end |
#name ⇒ Object (readonly)
- nil | Ident
-
the name of the block argument
2698 2699 2700 |
# File 'lib/syntax_tree.rb', line 2698 def name @name end |
Instance Method Details
#child_nodes ⇒ Object
2712 2713 2714 |
# File 'lib/syntax_tree.rb', line 2712 def child_nodes [name] end |
#format(q) ⇒ Object
2716 2717 2718 2719 |
# File 'lib/syntax_tree.rb', line 2716 def format(q) q.text("&") q.format(name) if name end |
#pretty_print(q) ⇒ Object
2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 |
# File 'lib/syntax_tree.rb', line 2721 def pretty_print(q) q.group(2, "(", ")") do q.text("blockarg") if name q.breakable q.pp(name) end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
2734 2735 2736 2737 2738 |
# File 'lib/syntax_tree.rb', line 2734 def to_json(*opts) { type: :blockarg, name: name, loc: location, cmts: comments }.to_json( *opts ) end |