# The RapEnumerable module adds functionality to facilitate the creation of # enumeration classes. # # Usage: # class Klass # include RapEnumerable #

# create(:id => 1, :aliases => [‘hello’, ‘there’]) # create(:id => 2, :aliases => [‘foo’, ‘bar’]) # # … # end # # * This ensures that instances of Klass can only be created from within Klass # by calling new_instance(attributes), where attributes is a hash used to set initial # values of instance variables, using the key as a method name and sending in the value. #

# * Instances of Klass will get methods id() and aliases() to retrieve these values. # # * Instances of Klass can be retrieved by calling Klass.find(key) where key is # an instance id or any of its aliases. #

# * Instances of Klass can be checked to see whether they are a particular instance by calling # <name>? for any of its indexed values. In the example above, you can take k, an instance # of Klass, and call k.hello? #

# * By default, the find method uses an index keyed by the id and aliases of the # Klass instances. You can add attributes to be used as finders by calling find_by as shown below. This # will also generate accessor methods for the given attribute names. Note that you must call # find_by before creating your enumeration instances. #

# For example, this will let you call Klass.find(1) or Klass.find(‘hello’) and get back the # instance: # class Klass # include RapEnumerable #

# find_by :name #

# create(:id => 1, :name => ‘hello’) # create(:id => 2, :name => ‘world’) # # end #

# * An array of all Klass instances can be retrieved with Klass.all # # Jeremy Lizt ([email protected]) - 4/2007