Last active
December 26, 2015 11:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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