Class: Prism::CallNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::CallNode
- Defined in:
- lib/prism/node.rb,
lib/prism/node_ext.rb,
ext/prism/api_node.c
Overview
Represents a method call, in all of the various forms that can take.
foo
^^^
foo()
^^^^^
+foo
^^^^
foo + bar
^^^^^^^^^
foo.bar
^^^^^^^
foo&.bar
^^^^^^^^
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
attr_reader arguments: ArgumentsNode?.
-
#block ⇒ Object
readonly
attr_reader block: Prism::node?.
-
#name ⇒ Object
readonly
attr_reader name: Symbol.
-
#receiver ⇒ Object
readonly
The object that the method is being called on.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#attribute_write? ⇒ Boolean
def attribute_write?: () -> bool.
-
#call_operator ⇒ Object
def call_operator: () -> String?.
-
#call_operator_loc ⇒ Object
attr_reader call_operator_loc: Location?.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String?.
-
#closing_loc ⇒ Object
attr_reader closing_loc: Location?.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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, block: self.block) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?name: Symbol, ?message_loc: Location?, ?opening_loc: Location?, ?arguments: ArgumentsNode?, ?closing_loc: Location?, ?block: Prism::node?) -> CallNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, name: Symbol, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, block: Prism::node? }.
-
#full_message_loc ⇒ Object
When a call node has the attribute_write flag set, it means that the call is using the attribute write syntax.
-
#ignore_visibility? ⇒ Boolean
def ignore_visibility?: () -> bool.
-
#initialize(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc, opening_loc, arguments, closing_loc, block) ⇒ CallNode
constructor
Initialize a new CallNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#message ⇒ Object
def message: () -> String?.
-
#message_loc ⇒ Object
attr_reader message_loc: Location?.
-
#opening ⇒ Object
def opening: () -> String?.
-
#opening_loc ⇒ Object
attr_reader opening_loc: Location?.
-
#safe_navigation? ⇒ Boolean
def safe_navigation?: () -> bool.
-
#type ⇒ Object
Return a symbol representation of this node type.
-
#variable_call? ⇒ Boolean
def variable_call?: () -> bool.
Constructor Details
#initialize(source, node_id, location, flags, receiver, call_operator_loc, name, message_loc, opening_loc, arguments, closing_loc, block) ⇒ CallNode
Initialize a new CallNode node.
2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 |
# File 'lib/prism/node.rb', line 2205 def initialize(source, node_id, location, flags, receiver, call_operator_loc, name, , opening_loc, arguments, closing_loc, block) @source = source @node_id = node_id @location = location @flags = flags @receiver = receiver @call_operator_loc = call_operator_loc @name = name @message_loc = @opening_loc = opening_loc @arguments = arguments @closing_loc = closing_loc @block = block end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
attr_reader arguments: ArgumentsNode?
2332 2333 2334 |
# File 'lib/prism/node.rb', line 2332 def arguments @arguments end |
#block ⇒ Object (readonly)
attr_reader block: Prism::node?
2348 2349 2350 |
# File 'lib/prism/node.rb', line 2348 def block @block end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
2303 2304 2305 |
# File 'lib/prism/node.rb', line 2303 def name @name end |
#receiver ⇒ Object (readonly)
The object that the method is being called on. This can be either ‘nil` or any [non-void expression](github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
foo.bar
^^^
+foo
^^^
foo + bar
^^^
2287 2288 2289 |
# File 'lib/prism/node.rb', line 2287 def receiver @receiver end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
2381 2382 2383 |
# File 'lib/prism/node.rb', line 2381 def self.type :call_node end |
Instance Method Details
#===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 |
# File 'lib/prism/node.rb', line 2387 def ===(other) other.is_a?(CallNode) && (flags === other.flags) && (receiver === other.receiver) && (call_operator_loc.nil? == other.call_operator_loc.nil?) && (name === other.name) && (.nil? == other..nil?) && (opening_loc.nil? == other.opening_loc.nil?) && (arguments === other.arguments) && (closing_loc.nil? == other.closing_loc.nil?) && (block === other.block) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
2221 2222 2223 |
# File 'lib/prism/node.rb', line 2221 def accept(visitor) visitor.visit_call_node(self) end |
#attribute_write? ⇒ Boolean
def attribute_write?: () -> bool
2268 2269 2270 |
# File 'lib/prism/node.rb', line 2268 def attribute_write? flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE) end |
#call_operator ⇒ Object
def call_operator: () -> String?
2351 2352 2353 |
# File 'lib/prism/node.rb', line 2351 def call_operator call_operator_loc&.slice end |
#call_operator_loc ⇒ Object
attr_reader call_operator_loc: Location?
2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 |
# File 'lib/prism/node.rb', line 2290 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 |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
2226 2227 2228 |
# File 'lib/prism/node.rb', line 2226 def child_nodes [receiver, arguments, block] end |
#closing ⇒ Object
def closing: () -> String?
2366 2367 2368 |
# File 'lib/prism/node.rb', line 2366 def closing closing_loc&.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location?
2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 |
# File 'lib/prism/node.rb', line 2335 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 |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
2240 2241 2242 |
# File 'lib/prism/node.rb', line 2240 def comment_targets [*receiver, *call_operator_loc, *, *opening_loc, *arguments, *closing_loc, *block] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
2231 2232 2233 2234 2235 2236 2237 |
# File 'lib/prism/node.rb', line 2231 def compact_child_nodes compact = [] #: Array[Prism::node] compact << receiver if receiver compact << arguments if arguments compact << block if block compact 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, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?name: Symbol, ?message_loc: Location?, ?opening_loc: Location?, ?arguments: ArgumentsNode?, ?closing_loc: Location?, ?block: Prism::node?) -> CallNode
2245 2246 2247 |
# File 'lib/prism/node.rb', line 2245 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., opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block) CallNode.new(source, node_id, location, flags, receiver, call_operator_loc, name, , opening_loc, arguments, closing_loc, block) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, name: Symbol, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, block: Prism::node? }
2253 2254 2255 |
# File 'lib/prism/node.rb', line 2253 def deconstruct_keys(keys) { node_id: node_id, location: location, receiver: receiver, call_operator_loc: call_operator_loc, name: name, message_loc: , opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block } end |
#full_message_loc ⇒ Object
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.
331 332 333 |
# File 'lib/prism/node_ext.rb', line 331 def attribute_write? ? &.adjoin("=") : end |
#ignore_visibility? ⇒ Boolean
def ignore_visibility?: () -> bool
2273 2274 2275 |
# File 'lib/prism/node.rb', line 2273 def ignore_visibility? flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY) end |
#inspect ⇒ Object
def inspect -> String
2371 2372 2373 |
# File 'lib/prism/node.rb', line 2371 def inspect InspectVisitor.compose(self) end |
#message ⇒ Object
def message: () -> String?
2356 2357 2358 |
# File 'lib/prism/node.rb', line 2356 def &.slice end |
#message_loc ⇒ Object
attr_reader message_loc: Location?
2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 |
# File 'lib/prism/node.rb', line 2306 def location = @message_loc case location when nil nil when Location location else @message_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#opening ⇒ Object
def opening: () -> String?
2361 2362 2363 |
# File 'lib/prism/node.rb', line 2361 def opening opening_loc&.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location?
2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 |
# File 'lib/prism/node.rb', line 2319 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 |
#safe_navigation? ⇒ Boolean
def safe_navigation?: () -> bool
2258 2259 2260 |
# File 'lib/prism/node.rb', line 2258 def flags.anybits?(CallNodeFlags::SAFE_NAVIGATION) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
2376 2377 2378 |
# File 'lib/prism/node.rb', line 2376 def type :call_node end |
#variable_call? ⇒ Boolean
def variable_call?: () -> bool
2263 2264 2265 |
# File 'lib/prism/node.rb', line 2263 def variable_call? flags.anybits?(CallNodeFlags::VARIABLE_CALL) end |