EnumSet: define a quick enum instance with named consts
Usage: initialize a new EnumSet
, passing a block declaring values:
FOOBAR = EnumSet.new do
value "FOO"
value "BAR"
end
This restuls in
FOOBAR::FOO -> "FOO"
FOOBAR::BAR -> "BAR"
FOOBAR.values -> ["FOO", "BAR"]
The returned intance is also an Enumerable
, so you can iteratre on it
directly using each
, map
, select
, and so on.
All values must be valid const names.
If you wish to use values that differ from the names, simply use a second argument
FOOBAR = EnumSet.new do
value "FOO", "foo"
value "BAR", "wahoo"
end
This restuls in
FOOBAR::FOO -> "foo"
FOOBAR::BAR -> "wahoo"
FOOBAR.values -> ["FOO", "BAR"]