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.



8839
8840
8841
8842
8843
8844
8845
# File 'lib/prism/node.rb', line 8839

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: LocalVariableReadNode | CallNode | ConstantReadNode | LocalVariableTargetNode



8881
8882
8883
# File 'lib/prism/node.rb', line 8881

def value
  @value
end

Class Method Details

.typeObject

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



8894
8895
8896
# File 'lib/prism/node.rb', line 8894

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.



8900
8901
8902
8903
# File 'lib/prism/node.rb', line 8900

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



8848
8849
8850
# File 'lib/prism/node.rb', line 8848

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



8853
8854
8855
# File 'lib/prism/node.rb', line 8853

def child_nodes
  [value]
end

#comment_targetsObject

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



8863
8864
8865
# File 'lib/prism/node.rb', line 8863

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



8858
8859
8860
# File 'lib/prism/node.rb', line 8858

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: LocalVariableReadNode | CallNode | ConstantReadNode | LocalVariableTargetNode) -> ImplicitNode



8868
8869
8870
# File 'lib/prism/node.rb', line 8868

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: LocalVariableReadNode | CallNode | ConstantReadNode | LocalVariableTargetNode }



8876
8877
8878
# File 'lib/prism/node.rb', line 8876

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

#inspectObject

def inspect -> String



8884
8885
8886
# File 'lib/prism/node.rb', line 8884

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



8889
8890
8891
# File 'lib/prism/node.rb', line 8889

def type
  :implicit_node
end