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.



17438
17439
17440
17441
17442
17443
17444
17445
# File 'lib/prism/node.rb', line 17438

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]



17481
17482
17483
# File 'lib/prism/node.rb', line 17481

def names
  @names
end

Class Method Details

.typeObject

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



17512
17513
17514
# File 'lib/prism/node.rb', line 17512

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.



17518
17519
17520
17521
17522
17523
# File 'lib/prism/node.rb', line 17518

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



17448
17449
17450
# File 'lib/prism/node.rb', line 17448

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

#child_nodesObject Also known as: deconstruct

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



17453
17454
17455
# File 'lib/prism/node.rb', line 17453

def child_nodes
  [*names]
end

#comment_targetsObject

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



17463
17464
17465
# File 'lib/prism/node.rb', line 17463

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



17458
17459
17460
# File 'lib/prism/node.rb', line 17458

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



17468
17469
17470
# File 'lib/prism/node.rb', line 17468

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 }



17476
17477
17478
# File 'lib/prism/node.rb', line 17476

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

#inspectObject

def inspect -> String



17502
17503
17504
# File 'lib/prism/node.rb', line 17502

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



17497
17498
17499
# File 'lib/prism/node.rb', line 17497

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



17484
17485
17486
17487
17488
# File 'lib/prism/node.rb', line 17484

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.



17492
17493
17494
# File 'lib/prism/node.rb', line 17492

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

#typeObject

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



17507
17508
17509
# File 'lib/prism/node.rb', line 17507

def type
  :undef_node
end