Class: SyntaxTree::RestParam
- Inherits:
-
Object
- Object
- SyntaxTree::RestParam
- Defined in:
- lib/syntax_tree.rb
Overview
RestParam represents defining a parameter in a method definition that accepts all remaining positional parameters.
def method(*rest) 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 parameter.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(name:, location:, comments: []) ⇒ RestParam
constructor
A new instance of RestParam.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(name:, location:, comments: []) ⇒ RestParam
Returns a new instance of RestParam.
10623 10624 10625 10626 10627 |
# File 'lib/syntax_tree.rb', line 10623 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
10621 10622 10623 |
# File 'lib/syntax_tree.rb', line 10621 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10618 10619 10620 |
# File 'lib/syntax_tree.rb', line 10618 def location @location end |
#name ⇒ Object (readonly)
- nil | Ident
-
the name of the parameter
10615 10616 10617 |
# File 'lib/syntax_tree.rb', line 10615 def name @name end |
Instance Method Details
#child_nodes ⇒ Object
10629 10630 10631 |
# File 'lib/syntax_tree.rb', line 10629 def child_nodes [name] end |
#format(q) ⇒ Object
10633 10634 10635 10636 |
# File 'lib/syntax_tree.rb', line 10633 def format(q) q.text("*") q.format(name) if name end |
#pretty_print(q) ⇒ Object
10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 |
# File 'lib/syntax_tree.rb', line 10638 def pretty_print(q) q.group(2, "(", ")") do q.text("rest_param") q.breakable q.pp(name) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
10649 10650 10651 10652 10653 |
# File 'lib/syntax_tree.rb', line 10649 def to_json(*opts) { type: :rest_param, name: name, loc: location, cmts: comments }.to_json( *opts ) end |