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

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of FCall.



4354
4355
4356
4357
4358
4359
# File 'lib/syntax_tree/node.rb', line 4354

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



4349
4350
4351
# File 'lib/syntax_tree/node.rb', line 4349

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



4352
4353
4354
# File 'lib/syntax_tree/node.rb', line 4352

def comments
  @comments
end

#valueObject (readonly)

Const | Ident

the name of the method



4346
4347
4348
# File 'lib/syntax_tree/node.rb', line 4346

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



4361
4362
4363
# File 'lib/syntax_tree/node.rb', line 4361

def accept(visitor)
  visitor.visit_fcall(self)
end

#child_nodesObject Also known as: deconstruct



4365
4366
4367
# File 'lib/syntax_tree/node.rb', line 4365

def child_nodes
  [value, arguments]
end

#deconstruct_keys(_keys) ⇒ Object



4371
4372
4373
4374
4375
4376
4377
4378
# File 'lib/syntax_tree/node.rb', line 4371

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

#format(q) ⇒ Object



4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
# File 'lib/syntax_tree/node.rb', line 4380

def format(q)
  q.format(value)

  if arguments.is_a?(ArgParen) && arguments.arguments.nil? &&
       !value.is_a?(Const)
    # If you're using an explicit set of parentheses on something that looks
    # like a constant, then we need to match that in order to maintain valid
    # Ruby. For example, you could do something like Foo(), on which we
    # would need to keep the parentheses to make it look like a method call.
  else
    q.format(arguments)
  end
end