Topic: Logical operations on constants

I am new to R on R so please excuse any ignorance of basics and just point me to the right place to learn if Im asking the obvious smile

In an effort to make my code easier to read, I am switching from a series of integers representing flags
(eg Jan = 1, Feb = 2, March = 4, April = 8) etc to constants.

I was looking for a way to create enumerations, but it seems that thy dont exist per se in Ruby, and the only site I could find that pointed me in this direction was to create a new model that simply contained my constants. Then in my code, instead of having month = 8, I can write month = Months::APRIL.

This is fine, and is more readable et, but it got me thinking.

I had a list of checkboxes on my page, and the user selected Jan and April, I can easily send to the database Months::JANUARY + Months::APRIL. But when I pull them back, 9 obviously doesnt match any of my constants.

So what is the best strategy for reading an integer from the database, and converting it back into an array of flags or constants ?

Thanks
K

Re: Logical operations on constants

You'd have to mess about with modulus and integer arithemetic, iterating down from December to January. Not a pretty solution.