#!/usr/bin/env ruby # This code comes from http://ruby-it.org/pages/Hash+Infinito # Check the page for copyright notice and explanations >> superhash['primo']= "alore" => "alore" >> superhash['due']['livelli'] => {} >> superhash['due']['livelli']= 'ciao' => "ciao" >> superhash => {"primo"=>"alore", "due"=>{"livelli"=>"ciao"}} >> superhash[:tutti][:i]['livelli']['che']["desiderate"]= "bau" => "bau" >> superhash => {"primo"=>"alore","due"=>{"livelli"=>"ciao"}, :tutti=>{:i=>{"livelli"=>{"che"=>{"desiderate"=>"bau"}}}}} >> hash_maker = proc do |h, k| ?> h[k] = Hash.new(&hash_maker) >> end => # >> sala=Hash.new &hash_maker => {} >> sala[0][1]='signor rossi' => "signor rossi" >> sala[2][20]='signora bianchi' => "signora bianchi" >> sala[5][12]='signor mori' => "signor mori" >> sala.size => 3 >> x=0 => 0 >> ary=Array.new(10) { x+=1 } => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >> hsh=Hash.new {|hash,kiave| hash[kiave]=x+=1 } => {} >> hsh[:a] => 11 >> hsh[:s] => 12 >> hsh[29] => 13