Skip to content

Latest commit

 

History

History
executable file
·
37 lines (25 loc) · 864 Bytes

README.textile

File metadata and controls

executable file
·
37 lines (25 loc) · 864 Bytes

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: