Class: SyntaxTree::ArgParen

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ArgParen.



985
986
987
988
989
# File 'lib/syntax_tree.rb', line 985

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



977
978
979
# File 'lib/syntax_tree.rb', line 977

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



983
984
985
# File 'lib/syntax_tree.rb', line 983

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



980
981
982
# File 'lib/syntax_tree.rb', line 980

def location
  @location
end

Instance Method Details

#child_nodesObject



991
992
993
# File 'lib/syntax_tree.rb', line 991

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
# File 'lib/syntax_tree.rb', line 995

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

#pretty_print(q) ⇒ Object



1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
# File 'lib/syntax_tree.rb', line 1010

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("arg_paren")

    q.breakable
    q.pp(arguments)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



1021
1022
1023
1024
1025
1026
1027
1028
# File 'lib/syntax_tree.rb', line 1021

def to_json(*opts)
  {
    type: :arg_paren,
    args: arguments,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end