Skip to content

Instantly share code, notes, and snippets.

@eladmeidar
Forked from emirikol/gist:4551711
Created January 17, 2013 07:30
Show Gist options
  • Save eladmeidar/4554324 to your computer and use it in GitHub Desktop.
Save eladmeidar/4554324 to your computer and use it in GitHub Desktop.
class Enum < Hash
def initialize(*members)
super()
@rev = {}
members.each_with_index {|m,i| self[i] = m }
end
def [](k)
super || @rev[k] # || raise ArgumentError, "#{k} is not a member of this enum"
end
def []=(k,v)
@rev[v] = k
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment