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.



1036
1037
1038
1039
1040
# File 'lib/syntax_tree.rb', line 1036

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



1028
1029
1030
# File 'lib/syntax_tree.rb', line 1028

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1034
1035
1036
# File 'lib/syntax_tree.rb', line 1034

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1031
1032
1033
# File 'lib/syntax_tree.rb', line 1031

def location
  @location
end

Instance Method Details

#child_nodesObject



1042
1043
1044
# File 'lib/syntax_tree.rb', line 1042

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
# File 'lib/syntax_tree.rb', line 1046

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



1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
# File 'lib/syntax_tree.rb', line 1061

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



1072
1073
1074
1075
1076
1077
1078
1079
# File 'lib/syntax_tree.rb', line 1072

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