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:, location:, comments: []) ⇒ FCall

Returns a new instance of FCall.



5489
5490
5491
5492
5493
# File 'lib/syntax_tree.rb', line 5489

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5487
5488
5489
# File 'lib/syntax_tree.rb', line 5487

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



5484
5485
5486
# File 'lib/syntax_tree.rb', line 5484

def location
  @location
end

#valueObject (readonly)

Const | Ident

the name of the method



5481
5482
5483
# File 'lib/syntax_tree.rb', line 5481

def value
  @value
end

Instance Method Details

#child_nodesObject



5495
5496
5497
# File 'lib/syntax_tree.rb', line 5495

def child_nodes
  [value]
end

#format(q) ⇒ Object



5499
5500
5501
# File 'lib/syntax_tree.rb', line 5499

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

#pretty_print(q) ⇒ Object



5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
# File 'lib/syntax_tree.rb', line 5503

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



5514
5515
5516
5517
5518
# File 'lib/syntax_tree.rb', line 5514

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