class SyntaxTree::ArgParen

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()

Attributes

arguments[R]
nil | Args | ArgsForward

the arguments inside the

parentheses

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

Public Class Methods

new(arguments:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 735
def initialize(arguments:, location:)
  @arguments = arguments
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 784
def ===(other)
  other.is_a?(ArgParen) && arguments === other.arguments
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 741
def accept(visitor)
  visitor.visit_arg_paren(self)
end
arity() click to toggle source
# File lib/syntax_tree/node.rb, line 788
def arity
  arguments&.arity || 0
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 745
def child_nodes
  [arguments]
end
Also aliased as: deconstruct
copy(arguments: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 749
def copy(arguments: nil, location: nil)
  node =
    ArgParen.new(
      arguments: arguments || self.arguments,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 762
def deconstruct_keys(_keys)
  { arguments: arguments, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 766
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