Module: RubyVM::RJIT::CPointer

Defined in:
lib/ruby_vm/rjit/c_pointer.rb

Overview

Every class under this namespace is a pointer. Even if the type is immediate, it shouldn’t be dereferenced until ‘*` is called.

Defined Under Namespace

Classes: Array, BitField, Bool, Immediate, Pointer, Struct, Union

Class Method Summary collapse

Class Method Details

.with_class_name(prefix, name, cache: false, &block) ⇒ Object

Give a name to a dynamic CPointer class to see it on inspect



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/ruby_vm/rjit/c_pointer.rb', line 374

def self.with_class_name(prefix, name, cache: false, &block)
  return block.call if !name.nil? && name.empty?

  # Use a cached result only if cache: true
  class_name = "#{prefix}_#{name}"
  klass =
    if cache && self.const_defined?(class_name)
      self.const_get(class_name)
    else
      block.call
    end

  # Give it a name unless it's already defined
  unless self.const_defined?(class_name)
    self.const_set(class_name, klass)
  end

  klass
end