Class: Prism::IndexTargetNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::IndexTargetNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Represents assigning to an index.
foo[bar], = 1
^^^^^^^^
begin
rescue => foo[bar]
^^^^^^^^
end
for foo[bar] in baz do end
^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :index_target_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#arguments ⇒ ArgumentsNode?
:call-seq: arguments -> ArgumentsNode | nil.
-
#attribute_write? ⇒ Boolean
:category: Flags a call that is an attribute write, so the value being written should be returned.
-
#block ⇒ BlockArgumentNode?
:call-seq: block -> BlockArgumentNode | nil.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#closing ⇒ String
:call-seq: closing -> String.
-
#closing_loc ⇒ Location
:category: Locations :call-seq: closing_loc -> Location.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block) ⇒ IndexTargetNode
:call-seq: copy(**fields) -> IndexTargetNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#ignore_visibility? ⇒ Boolean
:category: Flags a call that ignores method visibility.
-
#initialize(source, node_id, location, flags, receiver, opening_loc, arguments, closing_loc, block) ⇒ IndexTargetNode
constructor
Initialize a new IndexTargetNode node.
-
#inspect ⇒ String
: () -> String.
-
#opening ⇒ String
:call-seq: opening -> String.
-
#opening_loc ⇒ Location
:category: Locations :call-seq: opening_loc -> Location.
-
#receiver ⇒ Prism::node
:call-seq: receiver -> Node.
-
#safe_navigation? ⇒ Boolean
:category: Flags &.
-
#save_closing_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.
-
#save_opening_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :index_target_node
See
Node#type. -
#variable_call? ⇒ Boolean
:category: Flags a call that could have been a local variable.
Constructor Details
#initialize(source, node_id, location, flags, receiver, opening_loc, arguments, closing_loc, block) ⇒ IndexTargetNode
Initialize a new IndexTargetNode node.
: (Source source, Integer node_id, Location location, Integer flags, Prism::node receiver, Location opening_loc, ArgumentsNode? arguments, Location closing_loc, BlockArgumentNode? block) -> void
17721 17722 17723 17724 17725 17726 17727 17728 17729 17730 17731 |
# File 'lib/prism/node.rb', line 17721 def initialize(source, node_id, location, flags, receiver, opening_loc, arguments, closing_loc, block) @source = source @node_id = node_id @location = location @flags = flags @receiver = receiver @opening_loc = opening_loc @arguments = arguments @closing_loc = closing_loc @block = block end |
Class Method Details
.type ⇒ :index_target_node
See Node.type.
: () -> :index_target_node
17822 17823 17824 |
# File 'lib/prism/node.rb', line 17822 def self.type :index_target_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
17964 17965 17966 17967 17968 17969 17970 17971 17972 |
# File 'lib/prism/node.rb', line 17964 def ===(other) # :nodoc: other.is_a?(IndexTargetNode) && (flags === other.flags) && (receiver === other.receiver) && (opening_loc.nil? == other.opening_loc.nil?) && (arguments === other.arguments) && (closing_loc.nil? == other.closing_loc.nil?) && (block === other.block) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
17747 17748 17749 |
# File 'lib/prism/node.rb', line 17747 def accept(visitor) visitor.visit_index_target_node(self) end |
#arguments ⇒ ArgumentsNode?
:call-seq:
arguments -> ArgumentsNode | nil
Returns the arguments attribute.
: () -> ArgumentsNode?
17903 17904 17905 |
# File 'lib/prism/node.rb', line 17903 def arguments @arguments end |
#attribute_write? ⇒ Boolean
:category: Flags a call that is an attribute write, so the value being written should be returned
: () -> bool
17853 17854 17855 |
# File 'lib/prism/node.rb', line 17853 def attribute_write? flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE) end |
#block ⇒ BlockArgumentNode?
:call-seq:
block -> BlockArgumentNode | nil
Returns the block attribute.
: () -> BlockArgumentNode?
17935 17936 17937 |
# File 'lib/prism/node.rb', line 17935 def block @block end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
17754 17755 17756 |
# File 'lib/prism/node.rb', line 17754 def child_nodes [receiver, arguments, block] end |
#closing ⇒ String
:call-seq:
closing -> String
Slice the location of closing_loc from the source.
: () -> String
17957 17958 17959 |
# File 'lib/prism/node.rb', line 17957 def closing closing_loc.slice end |
#closing_loc ⇒ Location
:category: Locations :call-seq:
closing_loc -> Location
Returns the Location represented by closing_loc.
: () -> Location
17914 17915 17916 17917 17918 |
# File 'lib/prism/node.rb', line 17914 def closing_loc location = @closing_loc return location if location.is_a?(Location) @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
17773 17774 17775 17776 17777 17778 17779 |
# File 'lib/prism/node.rb', line 17773 def compact_child_nodes compact = [] #: Array[Prism::node] compact << receiver if (arguments = self.arguments); compact << arguments; end if (block = self.block); compact << block; end compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block) ⇒ IndexTargetNode
:call-seq:
copy(**fields) -> IndexTargetNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node, ?opening_loc: Location, ?arguments: ArgumentsNode?, ?closing_loc: Location, ?block: BlockArgumentNode?) -> IndexTargetNode
17787 17788 17789 |
# File 'lib/prism/node.rb', line 17787 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block) IndexTargetNode.new(source, node_id, location, flags, receiver, opening_loc, arguments, closing_loc, block) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
17794 17795 17796 17797 17798 17799 17800 17801 17802 17803 17804 17805 17806 17807 17808 17809 17810 |
# File 'lib/prism/node.rb', line 17794 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location receiver opening_loc arguments closing_loc block opening closing]).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 :opening_loc then deconstructed[:opening_loc] = self.opening_loc when :arguments then deconstructed[:arguments] = self.arguments when :closing_loc then deconstructed[:closing_loc] = self.closing_loc when :block then deconstructed[:block] = self.block when :opening then deconstructed[:opening] = self.opening when :closing then deconstructed[:closing] = self.closing end end end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
17762 17763 17764 17765 17766 17767 17768 |
# File 'lib/prism/node.rb', line 17762 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield receiver if (arguments = self.arguments); yield arguments; end if (block = self.block); yield block; end end |
#ignore_visibility? ⇒ Boolean
:category: Flags a call that ignores method visibility
: () -> bool
17861 17862 17863 |
# File 'lib/prism/node.rb', line 17861 def ignore_visibility? flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY) end |
#inspect ⇒ String
: () -> String
17827 17828 17829 |
# File 'lib/prism/node.rb', line 17827 def inspect # :nodoc: InspectVisitor.compose(self) end |
#opening ⇒ String
:call-seq:
opening -> String
Slice the location of opening_loc from the source.
: () -> String
17947 17948 17949 |
# File 'lib/prism/node.rb', line 17947 def opening opening_loc.slice end |
#opening_loc ⇒ Location
:category: Locations :call-seq:
opening_loc -> Location
Returns the Location represented by opening_loc.
: () -> Location
17882 17883 17884 17885 17886 |
# File 'lib/prism/node.rb', line 17882 def opening_loc location = @opening_loc return location if location.is_a?(Location) @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#receiver ⇒ Prism::node
:call-seq:
receiver -> Node
Returns the receiver attribute.
: () -> Prism::node
17871 17872 17873 |
# File 'lib/prism/node.rb', line 17871 def receiver @receiver end |
#safe_navigation? ⇒ Boolean
:category: Flags &. operator
: () -> bool
17837 17838 17839 |
# File 'lib/prism/node.rb', line 17837 def flags.anybits?(CallNodeFlags::SAFE_NAVIGATION) end |
#save_closing_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
17925 17926 17927 |
# File 'lib/prism/node.rb', line 17925 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) end |
#save_opening_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
17893 17894 17895 |
# File 'lib/prism/node.rb', line 17893 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) end |
#type ⇒ :index_target_node
See Node#type.
: () -> :index_target_node
17815 17816 17817 |
# File 'lib/prism/node.rb', line 17815 def type :index_target_node end |
#variable_call? ⇒ Boolean
:category: Flags a call that could have been a local variable
: () -> bool
17845 17846 17847 |
# File 'lib/prism/node.rb', line 17845 def variable_call? flags.anybits?(CallNodeFlags::VARIABLE_CALL) end |