Class: Prism::UndefNode

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 undef keyword.

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

Explore code sample

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.

: (Source source, Integer node_id, Location location, Integer flags, Array[SymbolNode | InterpolatedSymbolNode] names, Location keyword_loc) -> void

Parameters:



31954
31955
31956
31957
31958
31959
31960
31961
# File 'lib/prism/node.rb', line 31954

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

Class Method Details

.type ⇒ :undef_node

See Node.type.

: () -> :undef_node

Returns:

  • (:undef_node)


32042
32043
32044
# File 'lib/prism/node.rb', line 32042

def self.type
  :undef_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


32100
32101
32102
32103
32104
32105
# File 'lib/prism/node.rb', line 32100

def ===(other) # :nodoc:
  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

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


31977
31978
31979
# File 'lib/prism/node.rb', line 31977

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


31984
31985
31986
# File 'lib/prism/node.rb', line 31984

def child_nodes
  [*names]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


32001
32002
32003
# File 'lib/prism/node.rb', line 32001

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

:call-seq:

copy(**fields) -> UndefNode

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

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

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • names: (Array[SymbolNode | InterpolatedSymbolNode]) (defaults to: self.names)
  • keyword_loc: (Location) (defaults to: self.keyword_loc)

Returns:



32011
32012
32013
# File 'lib/prism/node.rb', line 32011

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) ⇒ Hash[Symbol, untyped]

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


32018
32019
32020
32021
32022
32023
32024
32025
32026
32027
32028
32029
32030
# File 'lib/prism/node.rb', line 32018

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


31992
31993
31994
31995
31996
# File 'lib/prism/node.rb', line 31992

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

  names.each { |node| yield node }
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


32047
32048
32049
# File 'lib/prism/node.rb', line 32047

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)


32093
32094
32095
# File 'lib/prism/node.rb', line 32093

def keyword
  keyword_loc.slice
end

#keyword_loc ⇒ Location

:category: Locations :call-seq:

keyword_loc -> Location

Returns the Location represented by keyword_loc.

: () -> Location

Returns:



32070
32071
32072
32073
32074
# File 'lib/prism/node.rb', line 32070

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

#names ⇒ Array[SymbolNode | InterpolatedSymbolNode]

:call-seq:

names -> Array[SymbolNode | InterpolatedSymbolNode]

Returns the names attribute.

: () -> Array[SymbolNode | InterpolatedSymbolNode]

Returns:



32059
32060
32061
# File 'lib/prism/node.rb', line 32059

def names
  @names
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:



32081
32082
32083
# File 'lib/prism/node.rb', line 32081

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

#type ⇒ :undef_node

See Node#type.

: () -> :undef_node

Returns:

  • (:undef_node)


32035
32036
32037
# File 'lib/prism/node.rb', line 32035

def type
  :undef_node
end