I’m wondering what approaches people take to creating enumeration type
classes like Gender or State. At Rapleaf we wrote our own gem (with
accompanying rails plug-in, so the instances can easily be used as
attributes in your ActiveRecords). We packaged this up and discuss it in
a post on our blog. I’d love to get people’s feedback on whether this is
useful to them or if they’ve got alternative ideas.
Jeremy Lizt wrote:
I’m wondering what approaches people take to creating enumeration type
classes like Gender or State. At Rapleaf we wrote our own gem (with
accompanying rails plug-in, so the instances can easily be used as
attributes in your ActiveRecords). We packaged this up and discuss it in
a post on our blog. I’d love to get people’s feedback on whether this is
useful to them or if they’ve got alternative ideas.
http://svn.protocool.com/public/plugins/enumerations_mixin/ has
the advantage of caching all the values, but I like your use
of boolean methods so you can write
if object.enum.value?
rather than
if object.enum === :value
You have also implemented aliases, which would be useful.
–
We develop, watch us RoR, in numbers too big to ignore.