Class: SyntaxTree::FCall

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

Overview

FCall represents the piece of a method call that comes before any arguments (i.e., just the name of the method). It is used in places where the parser is sure that it is a method call and not potentially a local variable.

method(argument)

In the above example, it’s referring to the method segment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FCall.



5793
5794
5795
5796
5797
5798
# File 'lib/syntax_tree.rb', line 5793

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

Instance Attribute Details

#argumentsObject (readonly)

nil | ArgParen | Args

the arguments to the method call



5785
5786
5787
# File 'lib/syntax_tree.rb', line 5785

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5791
5792
5793
# File 'lib/syntax_tree.rb', line 5791

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



5788
5789
5790
# File 'lib/syntax_tree.rb', line 5788

def location
  @location
end

#valueObject (readonly)

Const | Ident

the name of the method



5782
5783
5784
# File 'lib/syntax_tree.rb', line 5782

def value
  @value
end

Instance Method Details

#child_nodesObject



5800
5801
5802
# File 'lib/syntax_tree.rb', line 5800

def child_nodes
  [value, arguments]
end

#format(q) ⇒ Object



5804
5805
5806
5807
# File 'lib/syntax_tree.rb', line 5804

def format(q)
  q.format(value)
  q.format(arguments)
end

#pretty_print(q) ⇒ Object



5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
# File 'lib/syntax_tree.rb', line 5809

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

    q.breakable
    q.pp(value)

    if arguments
      q.breakable
      q.pp(arguments)
    end

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

#to_json(*opts) ⇒ Object



5825
5826
5827
5828
5829
5830
5831
5832
5833
# File 'lib/syntax_tree.rb', line 5825

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