typed-enum

A TypedEnum offers an enumeration facility allowing for the expression of a constrained set of (enumerated) values of a user-defined class, akin to Java's concept of enum. It supports listing the available enumerated values and serializing/deserializing instances to/from string representations. It is not thread safe (though it could be made so relatively easily).

Basic Usage

A TypedEnum can be used to represent a typed, enumerated set of values. A TypedEnum offers the following features:

Basic usage example:

class Color
  @enum = lambda {[
    RED   = self.new(:red),
    GREEN = self.new(:green),
    BLUE  = self.new(:blue)
  ]}
  include TypedEnum
end

Color::RED => #<Color:0x163d59f8 @name=:red>
Color.from_name(:red) => #<Color:0x163d59f8 @name=:red>
Color.from_name('red') => #<Color:0x163d59f8 @name=:red>
Color::RED.name => :red
Color.values => [#<Color:0x163d59f8 @name=:red>, #<Color:0x163d59a8 @name=:green>, #<Color:0x163d5980 @name=:blue>]

Contributing to typed-enum

Copyright © 2011 Chris Tucker. See LICENSE.txt for further details.