With Reverse Lookup

Extends a hash to be able to look up keys by value (for bi-directional hashes).

Sample


table = {
  :foo => "Foo",
  :bar => "Bar",
  :baz => "Baz"
}.extend(WithReverseLookup)

table[:foo]   #=> "Foo"
table["Foo"]  #=> :foo

License

MIT

Copyright

Copyright © 2010 Matt Todd.