Class: Prism::ForwardingSuperNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c

Overview

Represents the use of the super keyword without parentheses or arguments, but which might have a block.

super
^^^^^

super { 123 }
^^^^^^^^^^^^^

Explore code sample If it has any other arguments, it would be a SuperNode instead.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, keyword_loc, block) ⇒ ForwardingSuperNode

Initialize a new ForwardingSuperNode node.

: (Source source, Integer node_id, Location location, Integer flags, Location keyword_loc, BlockNode? block) -> void

Parameters:



13770
13771
13772
13773
13774
13775
13776
13777
# File 'lib/prism/node.rb', line 13770

def initialize(source, node_id, location, flags, keyword_loc, block)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @block = block
end

Class Method Details

.type ⇒ :forwarding_super_node

See Node.type.

: () -> :forwarding_super_node

Returns:

  • (:forwarding_super_node)


13860
13861
13862
# File 'lib/prism/node.rb', line 13860

def self.type
  :forwarding_super_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


13922
13923
13924
13925
13926
# File 'lib/prism/node.rb', line 13922

def ===(other) # :nodoc:
  other.is_a?(ForwardingSuperNode) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (block === other.block)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


13793
13794
13795
# File 'lib/prism/node.rb', line 13793

def accept(visitor)
  visitor.visit_forwarding_super_node(self)
end

#block ⇒ BlockNode?

:call-seq:

block -> BlockNode | nil

All other arguments are forwarded as normal, except the original block is replaced with the new block.

: () -> BlockNode?

Returns:



13903
13904
13905
# File 'lib/prism/node.rb', line 13903

def block
  @block
end

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


13800
13801
13802
# File 'lib/prism/node.rb', line 13800

def child_nodes
  [block]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


13817
13818
13819
13820
13821
# File 'lib/prism/node.rb', line 13817

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  if (block = self.block); compact << block; end
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, block: self.block) ⇒ ForwardingSuperNode

:call-seq:

copy(**fields) -> ForwardingSuperNode

Creates a copy of self with the given fields, using self as the template.

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?block: BlockNode?) -> ForwardingSuperNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • keyword_loc: (Location) (defaults to: self.keyword_loc)
  • block: (BlockNode, nil) (defaults to: self.block)

Returns:



13829
13830
13831
# File 'lib/prism/node.rb', line 13829

def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, block: self.block)
  ForwardingSuperNode.new(source, node_id, location, flags, keyword_loc, block)
end

#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
# File 'lib/prism/node.rb', line 13836

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location keyword_loc block keyword]).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 :keyword_loc             then deconstructed[:keyword_loc] = self.keyword_loc
    when :block                   then deconstructed[:block] = self.block
    when :keyword                 then deconstructed[:keyword] = self.keyword
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


13808
13809
13810
13811
13812
# File 'lib/prism/node.rb', line 13808

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

  if (block = self.block); yield block; end
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


13865
13866
13867
# File 'lib/prism/node.rb', line 13865

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#keyword ⇒ String

:call-seq:

keyword -> String

Slice the location of keyword_loc from the source.

: () -> String

Returns:

  • (String)


13915
13916
13917
# File 'lib/prism/node.rb', line 13915

def keyword
  keyword_loc.slice
end

#keyword_loc ⇒ Location

:category: Locations :call-seq:

keyword_loc -> Location

super ^^^^^

super { 123 } ^^^^^

: () -> Location

Returns:



13882
13883
13884
13885
13886
# File 'lib/prism/node.rb', line 13882

def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#save_keyword_loc(repository) ⇒ Relocation::Entry

:category: Repository Save the keyword_loc location using the given saved source so that it can be retrieved later.

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



13893
13894
13895
# File 'lib/prism/node.rb', line 13893

def save_keyword_loc(repository)
  repository.enter(node_id, :keyword_loc)
end

#type ⇒ :forwarding_super_node

See Node#type.

: () -> :forwarding_super_node

Returns:

  • (:forwarding_super_node)


13853
13854
13855
# File 'lib/prism/node.rb', line 13853

def type
  :forwarding_super_node
end