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.



16205
16206
16207
16208
16209
16210
16211
# File 'lib/prism/node.rb', line 16205

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.



16262
16263
16264
# File 'lib/prism/node.rb', line 16262

def write
  @write
end

Class Method Details

.typeObject

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



16275
16276
16277
# File 'lib/prism/node.rb', line 16275

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.



16281
16282
16283
16284
16285
# File 'lib/prism/node.rb', line 16281

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



16214
16215
16216
# File 'lib/prism/node.rb', line 16214

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

#child_nodesObject Also known as: deconstruct

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



16219
16220
16221
# File 'lib/prism/node.rb', line 16219

def child_nodes
  [write]
end

#comment_targetsObject

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



16229
16230
16231
# File 'lib/prism/node.rb', line 16229

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



16224
16225
16226
# File 'lib/prism/node.rb', line 16224

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



16234
16235
16236
# File 'lib/prism/node.rb', line 16234

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 }



16242
16243
16244
# File 'lib/prism/node.rb', line 16242

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

#experimental_copy?Boolean

def experimental_copy?: () -> bool

Returns:

  • (Boolean)


16257
16258
16259
# File 'lib/prism/node.rb', line 16257

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

#experimental_everything?Boolean

def experimental_everything?: () -> bool

Returns:

  • (Boolean)


16252
16253
16254
# File 'lib/prism/node.rb', line 16252

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

#inspectObject

def inspect -> String



16265
16266
16267
# File 'lib/prism/node.rb', line 16265

def inspect
  InspectVisitor.compose(self)
end

#literal?Boolean

def literal?: () -> bool

Returns:

  • (Boolean)


16247
16248
16249
# File 'lib/prism/node.rb', line 16247

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

#typeObject

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



16270
16271
16272
# File 'lib/prism/node.rb', line 16270

def type
  :shareable_constant_node
end