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
Represents the arguments to the method call.
-
#block ⇒ Object
readonly
Represents the block that is being passed to the method.
-
#name ⇒ Object
readonly
Represents the name of the method being called.
-
#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
Represents the location of the call operator.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array.
-
#closing ⇒ Object
def closing: () -> String?.
-
#closing_loc ⇒ Object
Represents the location of the right parenthesis.
-
#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, equal_loc: self.equal_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?, ?equal_loc: Location?, ?block: BlockNode | BlockArgumentNode | nil) -> 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?, equal_loc: Location?, block: BlockNode | BlockArgumentNode | nil }.
-
#each_child_node {|receiver| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator.
-
#equal ⇒ Object
def equal: () -> String?.
-
#equal_loc ⇒ Object
Represents the location of the equal sign, in the case that this is an attribute write.
-
#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, equal_loc, block) ⇒ CallNode
constructor
Initialize a new CallNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#message ⇒ Object
def message: () -> String?.
-
#message_loc ⇒ Object
Represents the location of the message.
-
#opening ⇒ Object
def opening: () -> String?.
-
#opening_loc ⇒ Object
Represents the location of the left parenthesis.
-
#safe_navigation? ⇒ Boolean
def safe_navigation?: () -> bool.
-
#save_call_operator_loc(repository) ⇒ Object
Save the call_operator_loc location using the given saved source so that it can be retrieved later.
-
#save_closing_loc(repository) ⇒ Object
Save the closing_loc location using the given saved source so that it can be retrieved later.
-
#save_equal_loc(repository) ⇒ Object
Save the equal_loc location using the given saved source so that it can be retrieved later.
-
#save_message_loc(repository) ⇒ Object
Save the message_loc location using the given saved source so that it can be retrieved later.
-
#save_opening_loc(repository) ⇒ Object
Save the opening_loc location using the given saved source so that it can be retrieved later.
-
#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, equal_loc, block) ⇒ CallNode
Initialize a new CallNode node.
2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 |
# File 'lib/prism/node.rb', line 2760 def initialize(source, node_id, location, flags, receiver, call_operator_loc, name, , 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 = @opening_loc = opening_loc @arguments = arguments @closing_loc = closing_loc @equal_loc = equal_loc @block = block end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Represents the arguments to the method call. These can be any [non-void expressions](github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
foo(bar)
^^^
2932 2933 2934 |
# File 'lib/prism/node.rb', line 2932 def arguments @arguments end |
#block ⇒ Object (readonly)
Represents the block that is being passed to the method.
foo { |a| a }
^^^^^^^^^
2985 2986 2987 |
# File 'lib/prism/node.rb', line 2985 def block @block end |
#name ⇒ Object (readonly)
Represents the name of the method being called.
foo.bar # name `:foo`
^^^
2883 2884 2885 |
# File 'lib/prism/node.rb', line 2883 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
^^^
2852 2853 2854 |
# File 'lib/prism/node.rb', line 2852 def receiver @receiver end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See Node::type.
3023 3024 3025 |
# File 'lib/prism/node.rb', line 3023 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.
3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 |
# File 'lib/prism/node.rb', line 3029 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?) && (equal_loc.nil? == other.equal_loc.nil?) && (block === other.block) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
2777 2778 2779 |
# File 'lib/prism/node.rb', line 2777 def accept(visitor) visitor.visit_call_node(self) end |
#attribute_write? ⇒ Boolean
def attribute_write?: () -> bool
2833 2834 2835 |
# File 'lib/prism/node.rb', line 2833 def attribute_write? flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE) end |
#call_operator ⇒ Object
def call_operator: () -> String?
2988 2989 2990 |
# File 'lib/prism/node.rb', line 2988 def call_operator call_operator_loc&.slice end |
#call_operator_loc ⇒ Object
Represents the location of the call operator.
foo.bar
^
foo&.bar
^^
2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 |
# File 'lib/prism/node.rb', line 2861 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
2782 2783 2784 |
# File 'lib/prism/node.rb', line 2782 def child_nodes [receiver, arguments, block] end |
#closing ⇒ Object
def closing: () -> String?
3003 3004 3005 |
# File 'lib/prism/node.rb', line 3003 def closing closing_loc&.slice end |
#closing_loc ⇒ Object
Represents the location of the right parenthesis.
foo(bar)
^
2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 |
# File 'lib/prism/node.rb', line 2938 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]
2805 2806 2807 |
# File 'lib/prism/node.rb', line 2805 def comment_targets [*receiver, *call_operator_loc, *, *opening_loc, *arguments, *closing_loc, *equal_loc, *block] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
2796 2797 2798 2799 2800 2801 2802 |
# File 'lib/prism/node.rb', line 2796 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, equal_loc: self.equal_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?, ?equal_loc: Location?, ?block: BlockNode | BlockArgumentNode | nil) -> CallNode
2810 2811 2812 |
# File 'lib/prism/node.rb', line 2810 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, equal_loc: self.equal_loc, block: self.block) CallNode.new(source, node_id, location, flags, receiver, call_operator_loc, name, , opening_loc, arguments, closing_loc, equal_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?, equal_loc: Location?, block: BlockNode | BlockArgumentNode | nil }
2818 2819 2820 |
# File 'lib/prism/node.rb', line 2818 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, equal_loc: equal_loc, block: block } end |
#each_child_node {|receiver| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator
2787 2788 2789 2790 2791 2792 2793 |
# File 'lib/prism/node.rb', line 2787 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 |
#equal ⇒ Object
def equal: () -> String?
3008 3009 3010 |
# File 'lib/prism/node.rb', line 3008 def equal equal_loc&.slice end |
#equal_loc ⇒ Object
Represents the location of the equal sign, in the case that this is an attribute write.
foo.bar = value
^
foo[bar] = value
^
2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 |
# File 'lib/prism/node.rb', line 2963 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 |
#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.
334 335 336 |
# File 'lib/prism/node_ext.rb', line 334 def attribute_write? ? &.adjoin("=") : end |
#ignore_visibility? ⇒ Boolean
def ignore_visibility?: () -> bool
2838 2839 2840 |
# File 'lib/prism/node.rb', line 2838 def ignore_visibility? flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY) end |
#inspect ⇒ Object
def inspect -> String
3013 3014 3015 |
# File 'lib/prism/node.rb', line 3013 def inspect InspectVisitor.compose(self) end |
#message ⇒ Object
def message: () -> String?
2993 2994 2995 |
# File 'lib/prism/node.rb', line 2993 def &.slice end |
#message_loc ⇒ Object
Represents the location of the message.
foo.bar
^^^
2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 |
# File 'lib/prism/node.rb', line 2889 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?
2998 2999 3000 |
# File 'lib/prism/node.rb', line 2998 def opening opening_loc&.slice end |
#opening_loc ⇒ Object
Represents the location of the left parenthesis.
foo(bar)
^
2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 |
# File 'lib/prism/node.rb', line 2910 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
2823 2824 2825 |
# File 'lib/prism/node.rb', line 2823 def flags.anybits?(CallNodeFlags::SAFE_NAVIGATION) end |
#save_call_operator_loc(repository) ⇒ Object
Save the call_operator_loc location using the given saved source so that it can be retrieved later.
2875 2876 2877 |
# File 'lib/prism/node.rb', line 2875 def save_call_operator_loc(repository) repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil? end |
#save_closing_loc(repository) ⇒ Object
Save the closing_loc location using the given saved source so that it can be retrieved later.
2952 2953 2954 |
# File 'lib/prism/node.rb', line 2952 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) unless @closing_loc.nil? end |
#save_equal_loc(repository) ⇒ Object
Save the equal_loc location using the given saved source so that it can be retrieved later.
2977 2978 2979 |
# File 'lib/prism/node.rb', line 2977 def save_equal_loc(repository) repository.enter(node_id, :equal_loc) unless @equal_loc.nil? end |
#save_message_loc(repository) ⇒ Object
Save the message_loc location using the given saved source so that it can be retrieved later.
2903 2904 2905 |
# File 'lib/prism/node.rb', line 2903 def (repository) repository.enter(node_id, :message_loc) unless @message_loc.nil? end |
#save_opening_loc(repository) ⇒ Object
Save the opening_loc location using the given saved source so that it can be retrieved later.
2924 2925 2926 |
# File 'lib/prism/node.rb', line 2924 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) unless @opening_loc.nil? end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
3018 3019 3020 |
# File 'lib/prism/node.rb', line 3018 def type :call_node end |
#variable_call? ⇒ Boolean
def variable_call?: () -> bool
2828 2829 2830 |
# File 'lib/prism/node.rb', line 2828 def variable_call? flags.anybits?(CallNodeFlags::VARIABLE_CALL) end |