Skip to content

Instantly share code, notes, and snippets.

@ksss
Created February 21, 2014 10:11
Show Gist options
  • Select an option

  • Save ksss/9131853 to your computer and use it in GitHub Desktop.

Select an option

Save ksss/9131853 to your computer and use it in GitHub Desktop.
class HashDoubly
attr_accessor :key, :value
def initialize hash=nil
if hash
@key = hash.dup
@value = hash.dup.invert
else
@key = {}
@value = {}
end
end
end
hd = HashDoubly.new({
1 => "foo",
2 => "bar",
3 => "baz",
})
p hd.key[2] #=> "foo"
p hd.value["foo"] #=> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment