Skip to content

Instantly share code, notes, and snippets.

@mikeric
Last active December 26, 2015 11:29
Show Gist options
  • Save mikeric/7144173 to your computer and use it in GitHub Desktop.
Save mikeric/7144173 to your computer and use it in GitHub Desktop.
Initialize a new Hash that can be accessed through individual objects in it's array keys.
hash = Hash.new{|hash, key| hash[hash.keys.detect{|k| k.include?(key)}]}
hash[%w(foo bar baz)] = ['hello', 'world']
hash # => {["foo", "bar", "baz"] => ["hello", "world"]}
hash['foo'] # => ["hello", "world"]
hash['bar'] # => ["hello", "world"]
hash['baz'] # => ["hello", "world"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment