Skip to content

Instantly share code, notes, and snippets.

@aaronblohowiak
Created May 28, 2009 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronblohowiak/119453 to your computer and use it in GitHub Desktop.
Save aaronblohowiak/119453 to your computer and use it in GitHub Desktop.
>> a = Hash.new({})
=> {}
>> a["hi"]["pants"] = "clamdiggers"
=> "clamdiggers"
>> a.inspect
=> "{}"
>> a["hi"]
=> {"pants"=>"clamdiggers"}
>> #hmmmmm...
>>
>> a = Hash.new({})
=> {}
>> a.__id__
=> 3010760
>> a["frankenstein"]
=> {}
>> _.__id__
=> 3010770
>> a["frankenstein"]["pants"]
=> nil
>> a["frankenstein"]["pants"] = "happy times"
=> "happy times"
>> a["mona lisa"]["stolen"] = "carmen san diego"
=> "carmen san diego"
>> default = ObjectSpace._id2ref(3010770)
=> {"stolen"=>"carmen san diego", "pants"=>"happy times"}
>> #d'oh!
>> a = Hash.new(&(p=lambda{|h,k| h[k] = Hash.new(&p)}))
=> {}
>> a.__id__
=> 2828720
>> a["bride of chucky"]
=> {}
>> new_hsh_id = _.__id__
=> 2815430
>> a["bride of chucky"]["lips"]
=> {}
>> a["bride of chucky"]["lips"] = "killer"
=> "killer"
>> ObjectSpace._id2ref(new_hsh_id)
=> {"lips"=>"killer"}
>> a.inspect
=> "{\"bride of chucky\"=>{\"lips\"=>\"killer\"}}"
>> #yay!
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment