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.
2460 2461 2462 2463 2464 |
# File 'lib/syntax_tree.rb', line 2460 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
2458 2459 2460 |
# File 'lib/syntax_tree.rb', line 2458 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
2455 2456 2457 |
# File 'lib/syntax_tree.rb', line 2455 def location @location end |
#name ⇒ Object (readonly)
- Ident
-
the name of the block argument
2452 2453 2454 |
# File 'lib/syntax_tree.rb', line 2452 def name @name end |
Instance Method Details
#child_nodes ⇒ Object
2466 2467 2468 |
# File 'lib/syntax_tree.rb', line 2466 def child_nodes [name] end |
#format(q) ⇒ Object
2470 2471 2472 2473 |
# File 'lib/syntax_tree.rb', line 2470 def format(q) q.text("&") q.format(name) end |
#pretty_print(q) ⇒ Object
2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 |
# File 'lib/syntax_tree.rb', line 2475 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
2486 2487 2488 2489 2490 |
# File 'lib/syntax_tree.rb', line 2486 def to_json(*opts) { type: :blockarg, name: name, loc: location, cmts: comments }.to_json( *opts ) end |