Class: Prism::ForwardingSuperNode

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

Overview

Represents the use of the ‘super` keyword without parentheses or arguments.

super
^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, location) ⇒ ForwardingSuperNode

def initialize: (block: BlockNode?, location: Location) -> void



6764
6765
6766
6767
# File 'lib/prism/node.rb', line 6764

def initialize(block, location)
  @block = block
  @location = location
end

Instance Attribute Details

#blockObject (readonly)

attr_reader block: BlockNode?



6761
6762
6763
# File 'lib/prism/node.rb', line 6761

def block
  @block
end

Class Method Details

.typeObject

Similar to #type, this method returns a symbol that you can use for splitting on the type of the node without having to do a long === chain. Note that like #type, it will still be slower than using == for a single class, but should be faster in a case statement or an array comparison.

def self.type: () -> Symbol



6843
6844
6845
# File 'lib/prism/node.rb', line 6843

def self.type
  :forwarding_super_node
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



6770
6771
6772
# File 'lib/prism/node.rb', line 6770

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



6775
6776
6777
# File 'lib/prism/node.rb', line 6775

def child_nodes
  [block]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



6787
6788
6789
# File 'lib/prism/node.rb', line 6787

def comment_targets
  [*block]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



6780
6781
6782
6783
6784
# File 'lib/prism/node.rb', line 6780

def compact_child_nodes
  compact = []
  compact << block if block
  compact
end

#copy(**params) ⇒ Object

def copy: (**params) -> ForwardingSuperNode



6792
6793
6794
6795
6796
6797
# File 'lib/prism/node.rb', line 6792

def copy(**params)
  ForwardingSuperNode.new(
    params.fetch(:block) { block },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



6803
6804
6805
# File 'lib/prism/node.rb', line 6803

def deconstruct_keys(keys)
  { block: block, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object

def inspect(inspector: NodeInspector) -> String



6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
# File 'lib/prism/node.rb', line 6808

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  if (block = self.block).nil?
    inspector << "└── block: ∅\n"
  else
    inspector << "└── block:\n"
    inspector << block.inspect(inspector.child_inspector("    ")).delete_prefix(inspector.prefix)
  end
  inspector.to_str
end

#typeObject

Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform. Usually this is done by calling ‘[cls1, cls2].include?(node.class)` or putting the node into a case statement and doing `case node; when cls1; when cls2; end`. Both of these approaches are relatively slow because of the constant lookups, method calls, and/or array allocations.

Instead, you can call #type, which will return to you a symbol that you can use for comparison. This is faster than the other approaches because it uses a single integer comparison, but also because if you’re on CRuby you can take advantage of the fact that case statements with all symbol keys will use a jump table.

def type: () -> Symbol



6833
6834
6835
# File 'lib/prism/node.rb', line 6833

def type
  :forwarding_super_node
end