Re: enums 1.0 library / gem - safe enumeration types for ruby e.g. enum :Color, [:red, :green, :blue]
Gerald Bauer <[email protected]>
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAAxEZd-b+POcOvcCzoGxUfzOq5gVCpdjMaTp9jUeTsRKtHGQow@mail.gmail.com> |
Hello,
> Is it possible to assign a specific integer values to a symbol? For some
> symbols? Or perhaps all or no symbols?
FYI: I'm building a new library - for safe (algebraic) union data types
with enumerated variants.
Now you can go "wild" and use your own integers or strings or really anything.
Example:
data :Color, :Red, [1],
:Green, [2],
:Blue, [3]
# -or-
data :Color, :Red, ['red'],
:Green, ['green'],
:Blue, ['blue']
# -or-
data :Color, :Red, [1,'red'],
:Green, [2, 'green'],
:Blue, [3, 'blue']
# -or-
data :Color, :Red, [255, 0, 0],
:Green, [0, 255, 0],
:Blue, [0, 0, 255],
:Other, [:r, :g, :b]
and so on and so forth [1].
Happy coding with ruby (and algebraic data types). Cheers. Prost.
[1] https://github.com/s6ruby/safedata
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>