Class: Prism::UndefNode

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

Overview

Represents the use of the ‘undef` keyword.

undef :foo, :bar, :baz
^^^^^^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, names, keyword_loc) ⇒ UndefNode

Initialize a new UndefNode node.



17648
17649
17650
17651
17652
17653
17654
17655
# File 'lib/prism/node.rb', line 17648

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

Instance Attribute Details

#namesObject (readonly)

attr_reader names: Array[SymbolNode | InterpolatedSymbolNode]



17691
17692
17693
# File 'lib/prism/node.rb', line 17691

def names
  @names
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



17722
17723
17724
# File 'lib/prism/node.rb', line 17722

def self.type
  :undef_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.



17728
17729
17730
17731
17732
17733
# File 'lib/prism/node.rb', line 17728

def ===(other)
  other.is_a?(UndefNode) &&
    (names.length == other.names.length) &&
    names.zip(other.names).all? { |left, right| left === right } &&
    (keyword_loc.nil? == other.keyword_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



17658
17659
17660
# File 'lib/prism/node.rb', line 17658

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



17663
17664
17665
# File 'lib/prism/node.rb', line 17663

def child_nodes
  [*names]
end

#comment_targetsObject

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



17673
17674
17675
# File 'lib/prism/node.rb', line 17673

def comment_targets
  [*names, keyword_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



17668
17669
17670
# File 'lib/prism/node.rb', line 17668

def compact_child_nodes
  [*names]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, names: self.names, keyword_loc: self.keyword_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?names: Array[SymbolNode | InterpolatedSymbolNode], ?keyword_loc: Location) -> UndefNode



17678
17679
17680
# File 'lib/prism/node.rb', line 17678

def copy(node_id: self.node_id, location: self.location, flags: self.flags, names: self.names, keyword_loc: self.keyword_loc)
  UndefNode.new(source, node_id, location, flags, names, keyword_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, names: Array[SymbolNode | InterpolatedSymbolNode], keyword_loc: Location }



17686
17687
17688
# File 'lib/prism/node.rb', line 17686

def deconstruct_keys(keys)
  { node_id: node_id, location: location, names: names, keyword_loc: keyword_loc }
end

#inspectObject

def inspect -> String



17712
17713
17714
# File 'lib/prism/node.rb', line 17712

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



17707
17708
17709
# File 'lib/prism/node.rb', line 17707

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



17694
17695
17696
17697
17698
# File 'lib/prism/node.rb', line 17694

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) ⇒ Object

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



17702
17703
17704
# File 'lib/prism/node.rb', line 17702

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

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



17717
17718
17719
# File 'lib/prism/node.rb', line 17717

def type
  :undef_node
end