public
Description: Simple Ruby enumerations for when arrays of symbols won't do
Homepage:
Clone URL: git://github.com/karlin/enumeration.git
karlin (author)
Wed Jun 24 12:36:17 -0700 2009
commit  985d49ae83ed79cebd2069d3203cbc96bce75388
tree    da11694f9627494a1c88bfc02dd50da549707859
parent  1d0f1e907b2fe7429a2dfb92c009c9f7eb0b5b35
name age message
file LICENSE.txt Loading commit data...
file README.textile
file Rakefile Wed Jun 24 11:23:35 -0700 2009 added specs for frozen enum [karlin]
directory lib/
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: