Class: SyntaxTree::ArgParen
Overview
ArgParen represents wrapping arguments to a method inside a set of parentheses.
method(argument)
In the example above, there would be an ArgParen node around the Args node that represents the set of arguments being sent to the method method. The argument child node can be nil if no arguments were passed, as in:
method()
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
- nil | Args | ArgsForward
-
the arguments inside the parentheses.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(arguments:, location:, comments: []) ⇒ ArgParen
constructor
A new instance of ArgParen.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(arguments:, location:, comments: []) ⇒ ArgParen
Returns a new instance of ArgParen.
580 581 582 583 584 |
# File 'lib/syntax_tree/node.rb', line 580 def initialize(arguments:, location:, comments: []) @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- nil | Args | ArgsForward
-
the arguments inside the
parentheses
575 576 577 |
# File 'lib/syntax_tree/node.rb', line 575 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
578 579 580 |
# File 'lib/syntax_tree/node.rb', line 578 def comments @comments end |
Instance Method Details
#accept(visitor) ⇒ Object
586 587 588 |
# File 'lib/syntax_tree/node.rb', line 586 def accept(visitor) visitor.visit_arg_paren(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
590 591 592 |
# File 'lib/syntax_tree/node.rb', line 590 def child_nodes [arguments] end |
#deconstruct_keys(_keys) ⇒ Object
596 597 598 |
# File 'lib/syntax_tree/node.rb', line 596 def deconstruct_keys(_keys) { arguments: arguments, location: location, comments: comments } end |
#format(q) ⇒ Object
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
# File 'lib/syntax_tree/node.rb', line 600 def format(q) unless arguments q.text("()") return end q.text("(") q.group do q.indent do q.breakable_empty q.format(arguments) q.if_break { q.text(",") } if q.trailing_comma? && trailing_comma? end q.breakable_empty end q.text(")") end |