Class: SyntaxTree::ArgParen

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

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

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(arguments:, location:, comments: []) ⇒ ArgParen

Returns a new instance of ArgParen.



570
571
572
573
574
# File 'lib/syntax_tree/node.rb', line 570

def initialize(arguments:, location:, comments: [])
  @arguments = arguments
  @location = location
  @comments = comments
end

Instance Attribute Details

#argumentsObject (readonly)

nil | Args | ArgsForward

the arguments inside the

parentheses



565
566
567
# File 'lib/syntax_tree/node.rb', line 565

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



568
569
570
# File 'lib/syntax_tree/node.rb', line 568

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



576
577
578
# File 'lib/syntax_tree/node.rb', line 576

def accept(visitor)
  visitor.visit_arg_paren(self)
end

#child_nodesObject Also known as: deconstruct



580
581
582
# File 'lib/syntax_tree/node.rb', line 580

def child_nodes
  [arguments]
end

#deconstruct_keys(_keys) ⇒ Object



586
587
588
# File 'lib/syntax_tree/node.rb', line 586

def deconstruct_keys(_keys)
  { arguments: arguments, location: location, comments: comments }
end

#format(q) ⇒ Object



590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/syntax_tree/node.rb', line 590

def format(q)
  unless arguments
    q.text("()")
    return
  end

  q.group(0, "(", ")") do
    q.indent do
      q.breakable("")
      q.format(arguments)
    end
    q.breakable("")
  end
end