Skip to content

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

License

Notifications You must be signed in to change notification settings

karlin/enumeration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages