Module: ConstantCache::CacheMethods::InstanceMethods

Defined in:
lib/constant_cache/cache_methods.rb

Instance Method Summary collapse

Instance Method Details

#set_instance_as_constantObject

Create a constant on the class that pointing to an instance



64
65
66
67
68
69
70
71
72
73
# File 'lib/constant_cache/cache_methods.rb', line 64

def set_instance_as_constant
  const = constant_name
  if !const.blank?
    if self.class.const_defined?(const)
      message = "Constant #{self.class.to_s}::#{const} has already been defined"
      raise ConstantCache::DuplicateConstantError, message
    end
    self.class.const_set(const, self) if !const.blank?
  end
end