Posted By

pmd on 10/11/08


Tagged

hash


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


Create nested hashes


 / Published in: Ruby
 

URL: http://www.ruby-forum.com/topic/111524

  1. # From: http://www.ruby-forum.com/topic/111524
  2. # Author: Daniel Martin
  3.  
  4. a = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc) }
  5.  
  6. a[2][1]=2
  7. a[2][2][3]=4
  8. a[3][1][1][1]=1
  9.  
  10. p a #=> {2=>{1=>2, 2=>{3=>4}}, 3=>{1=>{1=>{1=>1}}}}

Report this snippet  

You need to login to post a comment.