Class: Prism::ImplicitNode

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

Overview

Represents a node that is implicitly being added to the tree but doesn’t correspond directly to a node in the source.

{ foo: }
  ^^^^

{ Foo: }
  ^^^^

foo in { bar: }
         ^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, value) ⇒ ImplicitNode

Initialize a new ImplicitNode node.



7717
7718
7719
7720
7721
7722
7723
# File 'lib/prism/node.rb', line 7717

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

Instance Attribute Details

#valueObject (readonly)

attr_reader value: Prism::node



7759
7760
7761
# File 'lib/prism/node.rb', line 7759

def value
  @value
end

Class Method Details

.typeObject

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



7772
7773
7774
# File 'lib/prism/node.rb', line 7772

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



7778
7779
7780
7781
# File 'lib/prism/node.rb', line 7778

def ===(other)
  other.is_a?(ImplicitNode) &&
    (value === other.value)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



7726
7727
7728
# File 'lib/prism/node.rb', line 7726

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

#child_nodesObject Also known as: deconstruct

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



7731
7732
7733
# File 'lib/prism/node.rb', line 7731

def child_nodes
  [value]
end

#comment_targetsObject

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



7741
7742
7743
# File 'lib/prism/node.rb', line 7741

def comment_targets
  [value] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



7736
7737
7738
# File 'lib/prism/node.rb', line 7736

def compact_child_nodes
  [value]
end

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

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node) -> ImplicitNode



7746
7747
7748
# File 'lib/prism/node.rb', line 7746

def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value)
  ImplicitNode.new(source, node_id, location, flags, value)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, value: Prism::node }



7754
7755
7756
# File 'lib/prism/node.rb', line 7754

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

#inspectObject

def inspect -> String



7762
7763
7764
# File 'lib/prism/node.rb', line 7762

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



7767
7768
7769
# File 'lib/prism/node.rb', line 7767

def type
  :implicit_node
end