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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of FCall.



4316
4317
4318
4319
4320
4321
# File 'lib/syntax_tree/node.rb', line 4316

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



4311
4312
4313
# File 'lib/syntax_tree/node.rb', line 4311

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



4314
4315
4316
# File 'lib/syntax_tree/node.rb', line 4314

def comments
  @comments
end

#valueObject (readonly)

Const | Ident

the name of the method



4308
4309
4310
# File 'lib/syntax_tree/node.rb', line 4308

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



4323
4324
4325
# File 'lib/syntax_tree/node.rb', line 4323

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

#child_nodesObject Also known as: deconstruct



4327
4328
4329
# File 'lib/syntax_tree/node.rb', line 4327

def child_nodes
  [value, arguments]
end

#deconstruct_keys(keys) ⇒ Object



4333
4334
4335
4336
4337
4338
4339
4340
# File 'lib/syntax_tree/node.rb', line 4333

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

#format(q) ⇒ Object



4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
# File 'lib/syntax_tree/node.rb', line 4342

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