How can I marshal a hash with arrays?

前端 未结 4 1856
醉话见心
醉话见心 2021-01-24 04:23

What should I do to marshal an hash of arrays? The following code only prints {}.

s = Hash.new
s.default = Array.new
s[0] <<          


        
4条回答
  •  粉色の甜心
    2021-01-24 05:03

    You can just create your hash structure while initialing Hash.new to avoid such trouble

    h = Hash.new{ |a,b| a[b] = [] }
    h[:my_key] << "my value"
    

提交回复
热议问题