Class: SyntaxTree::MethodAddArg

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

Overview

MethodAddArg represents a method call with arguments and parentheses.

method(argument)

MethodAddArg can also represent with a method on an object, as in:

object.method(argument)

Finally, MethodAddArg can represent calling a method with no receiver that ends in a ?. In this case, the parser knows it’s a method call and not a local variable, so it uses a MethodAddArg node as opposed to a VCall node, as in:

method?

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of MethodAddArg.



7673
7674
7675
7676
7677
7678
# File 'lib/syntax_tree.rb', line 7673

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the method call



7665
7666
7667
# File 'lib/syntax_tree.rb', line 7665

def arguments
  @arguments
end

#callObject (readonly)

Call | FCall

the method call



7662
7663
7664
# File 'lib/syntax_tree.rb', line 7662

def call
  @call
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7671
7672
7673
# File 'lib/syntax_tree.rb', line 7671

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7668
7669
7670
# File 'lib/syntax_tree.rb', line 7668

def location
  @location
end

Instance Method Details

#child_nodesObject



7680
7681
7682
# File 'lib/syntax_tree.rb', line 7680

def child_nodes
  [call, arguments]
end

#format(q) ⇒ Object



7684
7685
7686
7687
7688
# File 'lib/syntax_tree.rb', line 7684

def format(q)
  q.format(call)
  q.text(" ") if !arguments.is_a?(ArgParen) && arguments.parts.any?
  q.format(arguments)
end

#pretty_print(q) ⇒ Object



7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
# File 'lib/syntax_tree.rb', line 7690

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

    q.breakable
    q.pp(call)

    q.breakable
    q.pp(arguments)

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

#to_json(*opts) ⇒ Object



7704
7705
7706
7707
7708
7709
7710
7711
7712
# File 'lib/syntax_tree.rb', line 7704

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