Class: Prism::ShareableConstantNode

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

Overview

This node wraps a constant write to indicate that when the value is written, it should have its shareability state modified.

# shareable_constant_value: literal
C = { a: 1 }
^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, write) ⇒ ShareableConstantNode

Initialize a new ShareableConstantNode node.



17430
17431
17432
17433
17434
17435
17436
# File 'lib/prism/node.rb', line 17430

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

Instance Attribute Details

#writeObject (readonly)

The constant write that should be modified with the shareability state.



17494
17495
17496
# File 'lib/prism/node.rb', line 17494

def write
  @write
end

Class Method Details

.typeObject

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



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

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



17513
17514
17515
17516
17517
# File 'lib/prism/node.rb', line 17513

def ===(other)
  other.is_a?(ShareableConstantNode) &&
    (flags === other.flags) &&
    (write === other.write)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



17439
17440
17441
# File 'lib/prism/node.rb', line 17439

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



17444
17445
17446
# File 'lib/prism/node.rb', line 17444

def child_nodes
  [write]
end

#comment_targetsObject

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



17461
17462
17463
# File 'lib/prism/node.rb', line 17461

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



17456
17457
17458
# File 'lib/prism/node.rb', line 17456

def compact_child_nodes
  [write]
end

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

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?write: ConstantWriteNode | ConstantAndWriteNode | ConstantOrWriteNode | ConstantOperatorWriteNode | ConstantPathWriteNode | ConstantPathAndWriteNode | ConstantPathOrWriteNode | ConstantPathOperatorWriteNode) -> ShareableConstantNode



17466
17467
17468
# File 'lib/prism/node.rb', line 17466

def copy(node_id: self.node_id, location: self.location, flags: self.flags, write: self.write)
  ShareableConstantNode.new(source, node_id, location, flags, write)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, write: ConstantWriteNode | ConstantAndWriteNode | ConstantOrWriteNode | ConstantOperatorWriteNode | ConstantPathWriteNode | ConstantPathAndWriteNode | ConstantPathOrWriteNode | ConstantPathOperatorWriteNode }



17474
17475
17476
# File 'lib/prism/node.rb', line 17474

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

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

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

Yields:



17449
17450
17451
17452
17453
# File 'lib/prism/node.rb', line 17449

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield write
end

#experimental_copy?Boolean

def experimental_copy?: () -> bool

Returns:

  • (Boolean)


17489
17490
17491
# File 'lib/prism/node.rb', line 17489

def experimental_copy?
  flags.anybits?(ShareableConstantNodeFlags::EXPERIMENTAL_COPY)
end

#experimental_everything?Boolean

def experimental_everything?: () -> bool

Returns:

  • (Boolean)


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

def experimental_everything?
  flags.anybits?(ShareableConstantNodeFlags::EXPERIMENTAL_EVERYTHING)
end

#inspectObject

def inspect -> String



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

def inspect
  InspectVisitor.compose(self)
end

#literal?Boolean

def literal?: () -> bool

Returns:

  • (Boolean)


17479
17480
17481
# File 'lib/prism/node.rb', line 17479

def literal?
  flags.anybits?(ShareableConstantNodeFlags::LITERAL)
end

#typeObject

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



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

def type
  :shareable_constant_node
end