module RubyVM::MJIT::CPointer

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

Public Class Methods

with_class_name(prefix, name, cache: false, &block) click to toggle source

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

# File lib/mjit/c_pointer.rb, line 309
def self.with_class_name(prefix, name, cache: false, &block)
  return block.call if 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