Created
August 3, 2016 12:51
-
-
Save contribu/ee2bcad0dcd002b8770f7047bc5355e3 to your computer and use it in GitHub Desktop.
new_safe_hash.rb (multidimensional hash)
This file contains hidden or 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
def new_safe_hash() | |
ifnone = lambda { |hash, key| | |
hash[key] = Hash.new(&ifnone) | |
} | |
Hash.new(&ifnone) | |
end | |
a = new_safe_hash() | |
a['x']['y'] = 3 | |
puts a | |
# {"x"=>{"y"=>3}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment