For example I have this enum in ruby-on-rails:
class Foo < ActiveRecord::Base
enum color: [ :red, :green, :blue ]
end
By default, the index should be :red -> 0, :green -> 1, and so on.
I want to get the enum value by index, let's say from index 1, so the result should be :green. Is it possible to do this ?
Update:
Pseudo-code example:
Foo.colors.find_by_index(1) # returns :green
f.input :color, as: :select, collection: Foo.colors). The enum index would be the option value, and the enum value itself as the display text/label. Array doesn't fit for this case I think. Another way is using Hash, but here I would like to know if it's possible to get enum value by index.Foo.colors.keys(1) #=> "green"becuasecolorsis simply aHashWithIndifferentAccessso it acts very similar to aHashbut all theSymbolkeys are going to beStrings.