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.



9395
9396
9397
9398
9399
9400
9401
# File 'lib/prism/node.rb', line 9395

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



9444
9445
9446
# File 'lib/prism/node.rb', line 9444

def value
  @value
end

Class Method Details

.typeObject

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



9457
9458
9459
# File 'lib/prism/node.rb', line 9457

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.



9463
9464
9465
9466
# File 'lib/prism/node.rb', line 9463

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



9404
9405
9406
# File 'lib/prism/node.rb', line 9404

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



9409
9410
9411
# File 'lib/prism/node.rb', line 9409

def child_nodes
  [value]
end

#comment_targetsObject

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



9426
9427
9428
# File 'lib/prism/node.rb', line 9426

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



9421
9422
9423
# File 'lib/prism/node.rb', line 9421

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



9431
9432
9433
# File 'lib/prism/node.rb', line 9431

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 }



9439
9440
9441
# File 'lib/prism/node.rb', line 9439

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

#each_child_node {|value| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



9414
9415
9416
9417
9418
# File 'lib/prism/node.rb', line 9414

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield value
end

#inspectObject

def inspect -> String



9447
9448
9449
# File 'lib/prism/node.rb', line 9447

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



9452
9453
9454
# File 'lib/prism/node.rb', line 9452

def type
  :implicit_node
end