class Oso::Polar::PolarClass

Ruby code reloaders (i.e. the one used by rails) swap out the value of a constant on code changes. Because of this, we can't reliably call `is_a?` on the constant that was passed to `register_class`.

Example (where Foo is a class defined in foo.rb):

> klass = Foo
> Foo.new.is_a? klass
  => true
> ... user changes foo.rb ...
> Foo.new.is_a? klass
  => false

To solve this, when we need to access the class (e.g. during isa), we look it up using const_get, which will always return the up-to-date version of the class.

Attributes

anon_class[R]
name[R]

Public Class Methods

new(klass) click to toggle source
# File lib/oso/polar/host.rb, line 23
def initialize(klass)
  @name = klass.name
  # If the class doesn't have a name, it is anonymous, meaning we should
  # actually store it directly
  @anon_class = klass if klass.name.nil?
end

Public Instance Methods

get() click to toggle source
# File lib/oso/polar/host.rb, line 30
def get
  return anon_class if anon_class

  Object.const_get(name)
end