How can i use 'default_proc' in this code to get same output?

#!/usr/bin/ruby
list={“a”=>1,“b”=>2,“c”=>3,“d”=>4}
#Here, I like to use ‘default_proc’
my_hash=Hash.new{ |h,k| h[k]=Hash.new(&h.default_proc) }
my_hash[101][1012]=list
my_hash[103][1312]={“ms”=>100,“ss”=>22,“hing”=>435}
my_hash[105][2512]=list

puts “user_id |dt_id |item |qty”

#Here, How can I use ‘default_proc’?
my_hash.each do |k,v|
if v.is_a?Hash
@id=k
v.each do |k,v|
if v.is_a? Hash
@dt=k
if v.is_a? Hash
v.each do |k,v|
puts “#{@id} |#{@dt} |#{k} | #{v}”
end
end
end
end
end
end

output:
user_id |dt_id |item |qty
101 |1012 |a | 1
101 |1012 |b | 2
101 |1012 |c | 3
101 |1012 |d | 4
103 |1312 |ms | 100
103 |1312 |ss | 22
103 |1312 |hing | 435
105 |2512 |a | 1
105 |2512 |b | 2
105 |2512 |c | 3
105 |2512 |d | 4

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs