Class: SyntaxTree::FCall

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



5070
5071
5072
5073
5074
5075
# File 'lib/syntax_tree/node.rb', line 5070

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



5062
5063
5064
# File 'lib/syntax_tree/node.rb', line 5062

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5068
5069
5070
# File 'lib/syntax_tree/node.rb', line 5068

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



5065
5066
5067
# File 'lib/syntax_tree/node.rb', line 5065

def location
  @location
end

#valueObject (readonly)

Const | Ident

the name of the method



5059
5060
5061
# File 'lib/syntax_tree/node.rb', line 5059

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



5077
5078
5079
# File 'lib/syntax_tree/node.rb', line 5077

def child_nodes
  [value, arguments]
end

#deconstruct_keys(keys) ⇒ Object



5083
5084
5085
5086
5087
5088
5089
5090
# File 'lib/syntax_tree/node.rb', line 5083

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

#format(q) ⇒ Object



5092
5093
5094
5095
# File 'lib/syntax_tree/node.rb', line 5092

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

#pretty_print(q) ⇒ Object



5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
# File 'lib/syntax_tree/node.rb', line 5097

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



5113
5114
5115
5116
5117
5118
5119
5120
5121
# File 'lib/syntax_tree/node.rb', line 5113

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