public
Description: Simple Ruby enumerations for when arrays of symbols won't do
Homepage:
Clone URL: git://github.com/karlin/enumeration.git
name age message
file LICENSE.txt Wed Jun 24 12:36:17 -0700 2009 added license [karlin]
file README.textile Wed Jun 24 12:13:12 -0700 2009 updated README and rdoc [karlin]
file Rakefile Wed Jun 24 11:23:35 -0700 2009 added specs for frozen enum [karlin]
directory lib/ Wed Jun 24 12:13:12 -0700 2009 updated README and rdoc [karlin]
directory spec/ Wed Jun 24 11:57:20 -0700 2009 changed to use symbols, added README content [karlin]
README.textile

Enumeration

Between string and symbol array literals, hash literals, and constants in
modules or classes, Ruby users have plenty of options for enumeration
constructs. If you need more, try Enumeration.


irb> Melons = Enumeration.of :watermelon, :honeydew, :cantelope

irb> Melons::HONEYDEW
=> :honeydew

irb> Melons.enum
=> [:watermelon, :honeydew, :cantelope]

irb> Melons.to_s
=> ["watermelon", "honeydew", "cantelope"]

irb> Melons::Order
=> {:cantelope=>2, :watermelon=>0, :honeydew=>1}

You can also use an array of strings to construct an Enumeration:


irb> Colors = Enumeration.of %w{fuschia red bondi cerulean carnelian}

irb> Colors::BONDI
=> :bondi

Author: