Exception: NoSingletonError

Inherits:
TypeError
  • Object
show all
Defined in:
lib/attic/errors.rb

Overview

NoSingletonError

This error is raised when an attempt is made to access the attic of an object which does not have a singleton class.

This is a TypeError because it is not an exceptional condition. It is simply a condition that is not supported by the Attic module.

Usage

require 'attic'
class MyClass
  include Attic
  attic :name, :age
end

Constant Summary collapse

MEMBERS =

A Set of classes which do not have singleton classes (i.e. meta classes). This is used to prevent an exception the first time an attic is accessed. It’s populated dynamically at start time by simply checking whether the object has a singleton. This only needs to be done once per class.

We use a set here to avoid having to deal with duplicate values. Realistically there are only a few classes that do not have singleton classes. We could hard code them here which is not lost on us.

Set.new

Class Method Summary collapse

Class Method Details

.add_member(obj) ⇒ Object



51
52
53
# File 'lib/attic/errors.rb', line 51

def self.add_member(obj)
  MEMBERS.merge [self]
end

.member?(obj) ⇒ Boolean

Check if the given object is a member of the NoSingleton members list. This checks for the object itself and all of its ancestors. See the docs for ‘Enumerable#===` for more details.

Returns:

  • (Boolean)


47
48
49
# File 'lib/attic/errors.rb', line 47

def self.member?(obj)
  MEMBERS === obj
end