Class: Prism::CallTargetNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c

Overview

Represents assigning to a method call.

foo.bar, = 1
^^^^^^^

begin
rescue => foo.bar
          ^^^^^^^
end

for foo.bar in baz do end
    ^^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc) ⇒ CallTargetNode

Initialize a new CallTargetNode node.

: (Source source, Integer node_id, Location location, Integer flags, Prism::node receiver, Location call_operator_loc, Symbol name, Location message_loc) -> void

Parameters:

  • source (Source)
  • node_id (Integer)
  • location (Location)
  • flags (Integer)
  • receiver (Prism::node)
  • call_operator_loc (Location)
  • name (Symbol)
  • message_loc (Location)


5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
# File 'lib/prism/node.rb', line 5841

def initialize(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @receiver = receiver
  @call_operator_loc = call_operator_loc
  @name = name
  @message_loc = message_loc
end

Class Method Details

.type ⇒ :call_target_node

See Node.type.

: () -> :call_target_node

Returns:

  • (:call_target_node)


5934
5935
5936
# File 'lib/prism/node.rb', line 5934

def self.type
  :call_target_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


6094
6095
6096
6097
6098
6099
6100
6101
# File 'lib/prism/node.rb', line 6094

def ===(other) # :nodoc:
  other.is_a?(CallTargetNode) &&
    (flags === other.flags) &&
    (receiver === other.receiver) &&
    (call_operator_loc.nil? == other.call_operator_loc.nil?) &&
    (name === other.name) &&
    (message_loc.nil? == other.message_loc.nil?)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


5866
5867
5868
# File 'lib/prism/node.rb', line 5866

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

#attribute_write? ⇒ Boolean

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

: () -> bool

Returns:

  • (Boolean)


5965
5966
5967
# File 'lib/prism/node.rb', line 5965

def attribute_write?
  flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
end

#call_operator ⇒ String

:call-seq:

call_operator -> String

Slice the location of call_operator_loc from the source.

: () -> String

Returns:

  • (String)


6077
6078
6079
# File 'lib/prism/node.rb', line 6077

def call_operator
  call_operator_loc.slice
end

#call_operator_loc ⇒ Location

:category: Locations :call-seq:

call_operator_loc -> Location

Represents the Location of the call operator.

foo.bar = 1
   ^

Explore code sample

: () -> Location

Returns:



6008
6009
6010
6011
6012
# File 'lib/prism/node.rb', line 6008

def call_operator_loc
  location = @call_operator_loc
  return location if location.is_a?(Location)
  @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


5873
5874
5875
# File 'lib/prism/node.rb', line 5873

def child_nodes
  [receiver]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


5890
5891
5892
# File 'lib/prism/node.rb', line 5890

def compact_child_nodes
  [receiver]
end

#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) ⇒ CallTargetNode

:call-seq:

copy(**fields) -> CallTargetNode

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

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node, ?call_operator_loc: Location, ?name: Symbol, ?message_loc: Location) -> CallTargetNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • receiver: (Prism::node) (defaults to: self.receiver)
  • call_operator_loc: (Location) (defaults to: self.call_operator_loc)
  • name: (Symbol) (defaults to: self.name)
  • message_loc: (Location) (defaults to: self.message_loc)

Returns:



5900
5901
5902
# File 'lib/prism/node.rb', line 5900

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)
  CallTargetNode.new(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc)
end

#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
# File 'lib/prism/node.rb', line 5907

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location receiver call_operator_loc name message_loc call_operator message]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :receiver                then deconstructed[:receiver] = self.receiver
    when :call_operator_loc       then deconstructed[:call_operator_loc] = self.call_operator_loc
    when :name                    then deconstructed[:name] = self.name
    when :message_loc             then deconstructed[:message_loc] = self.message_loc
    when :call_operator           then deconstructed[:call_operator] = self.call_operator
    when :message                 then deconstructed[:message] = self.message
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


5881
5882
5883
5884
5885
# File 'lib/prism/node.rb', line 5881

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

  yield receiver
end

#ignore_visibility? ⇒ Boolean

:category: Flags a call that ignores method visibility

: () -> bool

Returns:

  • (Boolean)


5973
5974
5975
# File 'lib/prism/node.rb', line 5973

def ignore_visibility?
  flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


5939
5940
5941
# File 'lib/prism/node.rb', line 5939

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#message ⇒ String

:call-seq:

message -> String

Slice the location of message_loc from the source.

: () -> String

Returns:

  • (String)


6087
6088
6089
# File 'lib/prism/node.rb', line 6087

def message
  message_loc.slice
end

#message_loc ⇒ Location

:category: Locations :call-seq:

message_loc -> Location

Represents the Location of the message.

foo.bar = 1
    ^^^

Explore code sample

: () -> Location

Returns:



6054
6055
6056
6057
6058
# File 'lib/prism/node.rb', line 6054

def message_loc
  location = @message_loc
  return location if location.is_a?(Location)
  @message_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#name ⇒ Symbol

:call-seq:

name -> Symbol

Represents the name of the method being called.

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

Explore code sample

: () -> Symbol

Returns:

  • (Symbol)


6036
6037
6038
# File 'lib/prism/node.rb', line 6036

def name
  @name
end

#receiver ⇒ Prism::node

:call-seq:

receiver -> Node

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

foo.bar = 1
^^^

Explore code sample

: () -> Prism::node

Returns:

  • (Prism::node)


5990
5991
5992
# File 'lib/prism/node.rb', line 5990

def receiver
  @receiver
end

#safe_navigation? ⇒ Boolean

:category: Flags &. operator

: () -> bool

Returns:

  • (Boolean)


5949
5950
5951
# File 'lib/prism/node.rb', line 5949

def safe_navigation?
  flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
end

#save_call_operator_loc(repository) ⇒ Relocation::Entry

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

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



6019
6020
6021
# File 'lib/prism/node.rb', line 6019

def save_call_operator_loc(repository)
  repository.enter(node_id, :call_operator_loc)
end

#save_message_loc(repository) ⇒ Relocation::Entry

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

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



6065
6066
6067
# File 'lib/prism/node.rb', line 6065

def save_message_loc(repository)
  repository.enter(node_id, :message_loc)
end

#type ⇒ :call_target_node

See Node#type.

: () -> :call_target_node

Returns:

  • (:call_target_node)


5927
5928
5929
# File 'lib/prism/node.rb', line 5927

def type
  :call_target_node
end

#variable_call? ⇒ Boolean

:category: Flags a call that could have been a local variable

: () -> bool

Returns:

  • (Boolean)


5957
5958
5959
# File 'lib/prism/node.rb', line 5957

def variable_call?
  flags.anybits?(CallNodeFlags::VARIABLE_CALL)
end