Skip to content

Instantly share code, notes, and snippets.

@emirikol
Created January 16, 2013 22:50
Show Gist options
  • Save emirikol/4551711 to your computer and use it in GitHub Desktop.
Save emirikol/4551711 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