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

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FCall.



4899
4900
4901
4902
4903
4904
# File 'lib/syntax_tree/node.rb', line 4899

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



4894
4895
4896
# File 'lib/syntax_tree/node.rb', line 4894

def arguments
  @arguments
end

#commentsObject (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



4897
4898
4899
# File 'lib/syntax_tree/node.rb', line 4897

def comments
  @comments
end

#valueObject (readonly)

[Const | Ident] the name of the method



4891
4892
4893
# File 'lib/syntax_tree/node.rb', line 4891

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



4906
4907
4908
# File 'lib/syntax_tree/node.rb', line 4906

def child_nodes
  [value, arguments]
end

#deconstruct_keys(keys) ⇒ Object



4912
4913
4914
4915
4916
4917
4918
4919
# File 'lib/syntax_tree/node.rb', line 4912

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

#format(q) ⇒ Object



4921
4922
4923
4924
# File 'lib/syntax_tree/node.rb', line 4921

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

#pretty_print(q) ⇒ Object



4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
# File 'lib/syntax_tree/node.rb', line 4926

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



4942
4943
4944
4945
4946
4947
4948
4949
4950
# File 'lib/syntax_tree/node.rb', line 4942

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