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.



15811
15812
15813
15814
15815
15816
15817
15818
# File 'lib/prism/node.rb', line 15811

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]



15854
15855
15856
# File 'lib/prism/node.rb', line 15854

def names
  @names
end

Class Method Details

.typeObject

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



15879
15880
15881
# File 'lib/prism/node.rb', line 15879

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.



15885
15886
15887
15888
15889
15890
# File 'lib/prism/node.rb', line 15885

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



15821
15822
15823
# File 'lib/prism/node.rb', line 15821

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

#child_nodesObject Also known as: deconstruct

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



15826
15827
15828
# File 'lib/prism/node.rb', line 15826

def child_nodes
  [*names]
end

#comment_targetsObject

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



15836
15837
15838
# File 'lib/prism/node.rb', line 15836

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



15831
15832
15833
# File 'lib/prism/node.rb', line 15831

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



15841
15842
15843
# File 'lib/prism/node.rb', line 15841

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 }



15849
15850
15851
# File 'lib/prism/node.rb', line 15849

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

#inspectObject

def inspect -> String



15869
15870
15871
# File 'lib/prism/node.rb', line 15869

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



15864
15865
15866
# File 'lib/prism/node.rb', line 15864

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



15857
15858
15859
15860
15861
# File 'lib/prism/node.rb', line 15857

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

#typeObject

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



15874
15875
15876
# File 'lib/prism/node.rb', line 15874

def type
  :undef_node
end