class Prism::CallNode - Documentation for Ruby 4.1
Description: class Prism::CallNode: Represents a method call, in all of the various forms that can take. foo ^^^ foo() ^^^^^ +foo ^^^^ foo + bar ^^^^^^^^^
Keywords: ruby,class,Prism::CallNode

🔍

No recent searches

# class Prism::CallNode

Represents a method call, in all of the various forms that can take.

    foo
    ^^^

    foo()
    ^^^^^

    +foo
    ^^^^

    foo + bar
    ^^^^^^^^^

    foo.bar
    ^^^^^^^

    foo&.bar
    ^^^^^^^^

### Public Class Methods

new (source, node_id, location, flags, receiver, call_operator_loc, name, message_loc, opening_loc, arguments, closing_loc, equal_loc, block)
Source

    # File lib/prism/node.rb, line 4208
    def initialize(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc, opening_loc, arguments, closing_loc, equal_loc, block)
      @source = source
      @node_id = node_id
      @location = location
      @flags = flags
      @receiver = receiver
      @call_operator_loc = call_operator_loc
      @name = name
      @message_loc = message_loc
      @opening_loc = opening_loc
      @arguments = arguments
      @closing_loc = closing_loc
      @equal_loc = equal_loc
      @block = block
    end

Initialize a new `CallNode` node.

### Public Instance Methods

arguments → ArgumentsNode | nil
Source

    # File lib/prism/node.rb, line 4483
    def arguments
      @arguments
    end

Represents the arguments to the method call. These can be any non-void expressions.

    foo(bar)
        ^^^

block → BlockNode | BlockArgumentNode | nil
Source

    # File lib/prism/node.rb, line 4559
    def block
      @block
    end

Represents the block that is being passed to the method.

    foo { |a| a }
        ^^^^^^^^^

full_message_loc ()
Source

    # File lib/prism/node_ext.rb, line 384
    def full_message_loc
      attribute_write? ? message_loc&.adjoin("=") : message_loc
    end

When a call node has the attribute_write flag set, it means that the call is using the attribute write syntax. This is either a method call to []= or a method call to a method that ends with =. Either way, the = sign is present in the source.

`Prism` returns the `message_loc` without the = sign attached, because there can be any amount of space between the message and the = sign. However, sometimes you want the location of the full message including the inner space and the = sign. This method provides that.

name → Symbol
Source

    # File lib/prism/node.rb, line 4410
    def name
      @name
    end

Represents the name of the method being called.

    foo.bar # name `:foo`
    ^^^

receiver → Node | nil
Source

    # File lib/prism/node.rb, line 4364
    def receiver
      @receiver
    end

The object that the method is being called on. This can be either `nil` or any non-void expression.

    foo.bar
    ^^^

    +foo
     ^^^

    foo + bar
    ^^^

## Flags

### Public Instance Methods

attribute_write? ()
Source

    # File lib/prism/node.rb, line 4337
    def attribute_write?
      flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
    end

a call that is an attribute write, so the value being written should be returned

ignore_visibility? ()
Source

    # File lib/prism/node.rb, line 4345
    def ignore_visibility?
      flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
    end

a call that ignores method visibility

variable_call? ()
Source

    # File lib/prism/node.rb, line 4329
    def variable_call?
      flags.anybits?(CallNodeFlags::VARIABLE_CALL)
    end

a call that could have been a local variable

## Locations

### Public Instance Methods

call_operator_loc → Location | nil
Source

    # File lib/prism/node.rb, line 4381
    def call_operator_loc
      location = @call_operator_loc
      case location
      when nil
        nil
      when Location
        location
      else
        @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
      end
    end

Represents the `Location` of the call operator.

    foo.bar
       ^

    foo&.bar
       ^^

closing_loc → Location | nil
Source

    # File lib/prism/node.rb, line 4497
    def closing_loc
      location = @closing_loc
      case location
      when nil
        nil
      when Location
        location
      else
        @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
      end
    end

Represents the `Location` of the right parenthesis.

    foo(bar)
           ^

equal_loc → Location | nil
Source

    # File lib/prism/node.rb, line 4530
    def equal_loc
      location = @equal_loc
      case location
      when nil
        nil
      when Location
        location
      else
        @equal_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
      end
    end

Represents the `Location` of the equal sign, in the case that this is an attribute write.

    foo.bar = value
            ^

    foo[bar] = value
             ^

message_loc → Location | nil
Source

    # File lib/prism/node.rb, line 4424
    def message_loc
      location = @message_loc
      case location
      when nil
        nil
      when Location
        location
      else
        @message_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
      end
    end

Represents the `Location` of the message.

    foo.bar
        ^^^

opening_loc → Location | nil
Source

    # File lib/prism/node.rb, line 4454
    def opening_loc
      location = @opening_loc
      case location
      when nil
        nil
      when Location
        location
      else
        @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
      end
    end

Represents the `Location` of the left parenthesis.

    foo(bar)
       ^

## Node Interface

These methods are present on all subclasses of `Node`. Read the node interface docs for more information.

### Public Class Methods

type ()
Source

    # File lib/prism/node.rb, line 4306
    def self.type
      :call_node
    end

See `Node.type`.

### Public Instance Methods

accept (visitor)
Source

    # File lib/prism/node.rb, line 4238
    def accept(visitor)
      visitor.visit_call_node(self)
    end

See `Node.accept`.

child_nodes ()
Source

    # File lib/prism/node.rb, line 4245
    def child_nodes
      [receiver, arguments, block]
    end

See `Node.child_nodes`.

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 4275
    def comment_targets
      [*receiver, *call_operator_loc, *message_loc, *opening_loc, *arguments, *closing_loc, *equal_loc, *block] #: Array[Prism::node | Location]
    end

See `Node.comment_targets`.

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 4264
    def compact_child_nodes
      compact = [] #: Array[Prism::node]
      if (receiver = self.receiver); compact << receiver; end
      if (arguments = self.arguments); compact << arguments; end
      if (block = self.block); compact << block; end
      compact
    end

See `Node.compact_child_nodes`.

copy(**fields) → CallNode
Source

    # File lib/prism/node.rb, line 4285
    def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, name: self.name, message_loc: self.message_loc, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, equal_loc: self.equal_loc, block: self.block)
      CallNode.new(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc, opening_loc, arguments, closing_loc, equal_loc, block)
    end

Creates a copy of self with the given fields, using self as the template.

deconstruct ()
Alias for: child_nodes
each_child_node () { |receiver| ... }
Source

    # File lib/prism/node.rb, line 4253
    def each_child_node(&blk)
      return to_enum(:each_child_node) unless block_given?

      if (receiver = self.receiver); yield receiver; end
      if (arguments = self.arguments); yield arguments; end
      if (block = self.block); yield block; end
    end

See `Node.each_child_node`.

type ()
Source

    # File lib/prism/node.rb, line 4299
    def type
      :call_node
    end

See `Node#type`.

## Repository

Methods related to `Relocation`.

### Public Instance Methods

save_call_operator_loc (repository)
Source

    # File lib/prism/node.rb, line 4398
    def save_call_operator_loc(repository)
      repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil?
    end

Save the `call_operator_loc` location using the given saved source so that it can be retrieved later.

save_closing_loc (repository)
Source

    # File lib/prism/node.rb, line 4514
    def save_closing_loc(repository)
      repository.enter(node_id, :closing_loc) unless @closing_loc.nil?
    end

Save the `closing_loc` location using the given saved source so that it can be retrieved later.

save_equal_loc (repository)
Source

    # File lib/prism/node.rb, line 4547
    def save_equal_loc(repository)
      repository.enter(node_id, :equal_loc) unless @equal_loc.nil?
    end

Save the `equal_loc` location using the given saved source so that it can be retrieved later.

save_message_loc (repository)
Source

    # File lib/prism/node.rb, line 4441
    def save_message_loc(repository)
      repository.enter(node_id, :message_loc) unless @message_loc.nil?
    end

Save the `message_loc` location using the given saved source so that it can be retrieved later.

save_opening_loc (repository)
Source

    # File lib/prism/node.rb, line 4471
    def save_opening_loc(repository)
      repository.enter(node_id, :opening_loc) unless @opening_loc.nil?
    end

Save the `opening_loc` location using the given saved source so that it can be retrieved later.

## Slicing

### Public Instance Methods

call_operator → String | nil
Source

    # File lib/prism/node.rb, line 4571
    def call_operator
      call_operator_loc&.slice
    end

Slice the location of `call_operator_loc` from the source.

closing → String | nil
Source

    # File lib/prism/node.rb, line 4601
    def closing
      closing_loc&.slice
    end

Slice the location of `closing_loc` from the source.

equal → String | nil
Source

    # File lib/prism/node.rb, line 4611
    def equal
      equal_loc&.slice
    end

Slice the location of `equal_loc` from the source.

message → String | nil
Source

    # File lib/prism/node.rb, line 4581
    def message
      message_loc&.slice
    end

Slice the location of `message_loc` from the source.

opening → String | nil
Source

    # File lib/prism/node.rb, line 4591
    def opening
      opening_loc&.slice
    end

Slice the location of `opening_loc` from the source.