Created
November 10, 2012 00:37
-
-
Save dekz/4049240 to your computer and use it in GitHub Desktop.
autovivify
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
| z = {} | |
| z[:b][:c][:d] = 'e' | |
| # NoMethodError: undefined method `[]' for nil:NilClass | |
| hash_new = proc { Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) } } | |
| a = hash_new.call | |
| a[:b][:c][:d] = 'e' | |
| a | |
| # => {:b=>{:c=>{:d=>"e"}}} |
I thought ostruct could do this anyway but it can't. At least in whatever backs http://repl.it
What ruby are you targeting?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hell yeah. I've been using this too http://livescript.net/#property-access