I want to have a class with several attributes that saves weekdays with numeric values.
summary_weekday :integer
collection_weekday :integer
What you are looking for cannot be obtained by enum, as it will try to create methods like object.tuesday? for both of the enums, which is logically wrong.
I recall DataMapper ORM to have exactly this kind of support. For ActiveRecord, you will probably have to create getter and setter methods manually for these properties and map it there, like:
WEEKDAYS = %w(monday tuesday wednesday thursday friday saturday sunday)
def summary_weekday
WEEKDAYS[read_attribute(:summary_weekday).to_i]
end
def summary_weekday=(value)
write_attribute(:summary_weekday, WEEKDAYS.index(value.to_s))
end
The code above may need some mangling while typecasting etc. I know that this is not a generic proof and I will really love to know any better solution for this interesting problem; will certainly be very useful.
Courtesy - Ruby Forum
Hope this helps.