Class: Prism::SuperNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::SuperNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents the use of the super keyword with parentheses or arguments.
super()
^^^^^^^
super foo,
^^^^^^^^^^^^^^
If no arguments are provided (except for a block), it would be a ForwardingSuperNode instead.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Can be only
nilwhen there are empty parentheses, like ‘super()`. -
#block ⇒ Object
readonly
attr_reader block: BlockNode | BlockArgumentNode | nil.
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.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array.
-
#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, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc, block: self.block) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?lparen_loc: Location?, ?arguments: ArgumentsNode?, ?rparen_loc: Location?, ?block: BlockNode | BlockArgumentNode | nil) -> SuperNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, lparen_loc: Location?, arguments: ArgumentsNode?, rparen_loc: Location?, block: BlockNode | BlockArgumentNode | nil }.
-
#each_child_node {|arguments| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator.
-
#initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc, block) ⇒ SuperNode
constructor
Initialize a new SuperNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#keyword ⇒ Object
def keyword: () -> String.
-
#keyword_loc ⇒ Object
attr_reader keyword_loc: Location.
-
#lparen ⇒ Object
def lparen: () -> String?.
-
#lparen_loc ⇒ Object
attr_reader lparen_loc: Location?.
-
#rparen ⇒ Object
def rparen: () -> String?.
-
#rparen_loc ⇒ Object
attr_reader rparen_loc: Location?.
-
#save_keyword_loc(repository) ⇒ Object
Save the keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_lparen_loc(repository) ⇒ Object
Save the lparen_loc location using the given saved source so that it can be retrieved later.
-
#save_rparen_loc(repository) ⇒ Object
Save the rparen_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc, block) ⇒ SuperNode
Initialize a new SuperNode node.
18295 18296 18297 18298 18299 18300 18301 18302 18303 18304 18305 |
# File 'lib/prism/node.rb', line 18295 def initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc, block) @source = source @node_id = node_id @location = location @flags = flags @keyword_loc = keyword_loc @lparen_loc = lparen_loc @arguments = arguments @rparen_loc = rparen_loc @block = block end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Can be only nil when there are empty parentheses, like ‘super()`.
18384 18385 18386 |
# File 'lib/prism/node.rb', line 18384 def arguments @arguments end |
#block ⇒ Object (readonly)
attr_reader block: BlockNode | BlockArgumentNode | nil
18406 18407 18408 |
# File 'lib/prism/node.rb', line 18406 def block @block end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See Node::type.
18434 18435 18436 |
# File 'lib/prism/node.rb', line 18434 def self.type :super_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.
18440 18441 18442 18443 18444 18445 18446 18447 |
# File 'lib/prism/node.rb', line 18440 def ===(other) other.is_a?(SuperNode) && (keyword_loc.nil? == other.keyword_loc.nil?) && (lparen_loc.nil? == other.lparen_loc.nil?) && (arguments === other.arguments) && (rparen_loc.nil? == other.rparen_loc.nil?) && (block === other.block) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
18308 18309 18310 |
# File 'lib/prism/node.rb', line 18308 def accept(visitor) visitor.visit_super_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
18313 18314 18315 |
# File 'lib/prism/node.rb', line 18313 def child_nodes [arguments, block] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
18334 18335 18336 |
# File 'lib/prism/node.rb', line 18334 def comment_targets [keyword_loc, *lparen_loc, *arguments, *rparen_loc, *block] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
18326 18327 18328 18329 18330 18331 |
# File 'lib/prism/node.rb', line 18326 def compact_child_nodes compact = [] #: Array[Prism::node] compact << arguments if arguments compact << block if block compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc, block: self.block) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?lparen_loc: Location?, ?arguments: ArgumentsNode?, ?rparen_loc: Location?, ?block: BlockNode | BlockArgumentNode | nil) -> SuperNode
18339 18340 18341 |
# File 'lib/prism/node.rb', line 18339 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc, block: self.block) SuperNode.new(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc, block) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, lparen_loc: Location?, arguments: ArgumentsNode?, rparen_loc: Location?, block: BlockNode | BlockArgumentNode | nil }
18347 18348 18349 |
# File 'lib/prism/node.rb', line 18347 def deconstruct_keys(keys) { node_id: node_id, location: location, keyword_loc: keyword_loc, lparen_loc: lparen_loc, arguments: arguments, rparen_loc: rparen_loc, block: block } end |
#each_child_node {|arguments| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator
18318 18319 18320 18321 18322 18323 |
# File 'lib/prism/node.rb', line 18318 def each_child_node return to_enum(:each_child_node) unless block_given? yield arguments if arguments yield block if block end |
#inspect ⇒ Object
def inspect -> String
18424 18425 18426 |
# File 'lib/prism/node.rb', line 18424 def inspect InspectVisitor.compose(self) end |
#keyword ⇒ Object
def keyword: () -> String
18409 18410 18411 |
# File 'lib/prism/node.rb', line 18409 def keyword keyword_loc.slice end |
#keyword_loc ⇒ Object
attr_reader keyword_loc: Location
18352 18353 18354 18355 18356 |
# File 'lib/prism/node.rb', line 18352 def keyword_loc location = @keyword_loc return location if location.is_a?(Location) @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#lparen ⇒ Object
def lparen: () -> String?
18414 18415 18416 |
# File 'lib/prism/node.rb', line 18414 def lparen lparen_loc&.slice end |
#lparen_loc ⇒ Object
attr_reader lparen_loc: Location?
18365 18366 18367 18368 18369 18370 18371 18372 18373 18374 18375 |
# File 'lib/prism/node.rb', line 18365 def lparen_loc location = @lparen_loc case location when nil nil when Location location else @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#rparen ⇒ Object
def rparen: () -> String?
18419 18420 18421 |
# File 'lib/prism/node.rb', line 18419 def rparen rparen_loc&.slice end |
#rparen_loc ⇒ Object
attr_reader rparen_loc: Location?
18387 18388 18389 18390 18391 18392 18393 18394 18395 18396 18397 |
# File 'lib/prism/node.rb', line 18387 def rparen_loc location = @rparen_loc case location when nil nil when Location location else @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#save_keyword_loc(repository) ⇒ Object
Save the keyword_loc location using the given saved source so that it can be retrieved later.
18360 18361 18362 |
# File 'lib/prism/node.rb', line 18360 def save_keyword_loc(repository) repository.enter(node_id, :keyword_loc) end |
#save_lparen_loc(repository) ⇒ Object
Save the lparen_loc location using the given saved source so that it can be retrieved later.
18379 18380 18381 |
# File 'lib/prism/node.rb', line 18379 def save_lparen_loc(repository) repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil? end |
#save_rparen_loc(repository) ⇒ Object
Save the rparen_loc location using the given saved source so that it can be retrieved later.
18401 18402 18403 |
# File 'lib/prism/node.rb', line 18401 def save_rparen_loc(repository) repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil? end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
18429 18430 18431 |
# File 'lib/prism/node.rb', line 18429 def type :super_node end |