The way you use the hash is not valid in Ruby, because each individual value must be assigned to the hash first before moving on to the nested hash (I assume you were with PHP?), But you can use a virtualized hash:
my_hash = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc)} first_key = 1 second_key = 2 third_key = 3 my_hash[first_key][second_key][third_key] = 100 p my_hash #output: {1=>{2=>{3=>100}}}
So it will be convenient for you.
texasbruce
source share