First of all, this is not a duplicate of Enums in Ruby :)
The accepted answer of that question suggests this as a good way to represent enums in Ruby:
cl
You can always create a system that's like the Java version:
module Foo
class Value
attr_reader :value
def initialize(value)
# Save a frozen, immutable copy
@value = value.dup.freeze
end
# Patch in methods to make it appear more friendly and string-like
alias_method :to_s, :value
alias_method :inspect, :value
end
# Define constants
BAR = Value.new('bar')
BAZ = Value.new('baz')
BIZ = Value.new('biz')
end
puts Foo::BAR
# => bar