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
Source
# File lib/prism/node.rb, line 3396 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
Source
# File lib/prism/node.rb, line 3626 def arguments @arguments end
Represents the arguments to the method call. These can be any non-void expressions.
foo(bar)
^^^
Source
# File lib/prism/node.rb, line 3692 def block @block end
Represents the block that is being passed to the method.
foo { |a| a }
^^^^^^^^^
Source
# File lib/prism/node_ext.rb, line 340 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.
Source
# File lib/prism/node.rb, line 3563 def name @name end
Represents the name of the method being called.
foo.bar # name `:foo` ^^^
Source
# File lib/prism/node.rb, line 3523 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
Source
# File lib/prism/node.rb, line 3500 def attribute_write? flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE) end
a call that is an attribute write, so the value being written should be returned
Source
# File lib/prism/node.rb, line 3506 def ignore_visibility? flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY) end
a call that ignores method visibility
Source
# File lib/prism/node.rb, line 3494 def variable_call? flags.anybits?(CallNodeFlags::VARIABLE_CALL) end
a call that could have been a local variable
Locations
Public Instance Methods
Source
# File lib/prism/node.rb, line 3538 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 ^^
Source
# File lib/prism/node.rb, line 3638 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)
^
Source
# File lib/prism/node.rb, line 3667 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
^
Source
# File lib/prism/node.rb, line 3575 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
^^^
Source
# File lib/prism/node.rb, line 3601 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
Public Class Methods
Public Instance Methods
Source
# File lib/prism/node.rb, line 3424 def accept(visitor) visitor.visit_call_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 3429 def child_nodes [receiver, arguments, block] end
See Node.child_nodes.
Source
# File lib/prism/node.rb, line 3452 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.
Source
# File lib/prism/node.rb, line 3443 def compact_child_nodes compact = [] #: Array[Prism::node] compact << receiver if receiver compact << arguments if arguments compact << block if block compact end
Source
# File lib/prism/node.rb, line 3460 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.
Source
# File lib/prism/node.rb, line 3434 def each_child_node return to_enum(:each_child_node) unless block_given? yield receiver if receiver yield arguments if arguments yield block if block end
See Node.each_child_node.
Repository
Public Instance Methods
Source
# File lib/prism/node.rb, line 3553 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.
Source
# File lib/prism/node.rb, line 3653 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.
Source
# File lib/prism/node.rb, line 3682 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.
Source
# File lib/prism/node.rb, line 3590 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.
Source
# File lib/prism/node.rb, line 3616 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
Source
# File lib/prism/node.rb, line 3702 def call_operator call_operator_loc&.slice end
Slice the location of call_operator_loc from the source.
Source
# File lib/prism/node.rb, line 3726 def closing closing_loc&.slice end
Slice the location of closing_loc from the source.
Source
# File lib/prism/node.rb, line 3734 def equal equal_loc&.slice end
Slice the location of equal_loc from the source.
Source
# File lib/prism/node.rb, line 3710 def message message_loc&.slice end
Slice the location of message_loc from the source.
Source
# File lib/prism/node.rb, line 3718 def opening opening_loc&.slice end
Slice the location of opening_loc from the source.