Skip to content

Instantly share code, notes, and snippets.

@amalc
Forked from eladmeidar/gist:4554324
Created March 16, 2014 18:19
Show Gist options
  • Save amalc/9587533 to your computer and use it in GitHub Desktop.
Save amalc/9587533 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