karlin / enumeration

Simple Ruby enumerations for when arrays of symbols won't do

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

About

Simple Ruby enumerations for when arrays of symbols won't do

License:MIT License


Languages

Language:Ruby 100.0%