且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ruby 将数组转换为嵌套哈希

更新时间:2023-02-14 10:56:01

试试这个:

array.reverse.inject(value) { |assigned_value, key| { key => assigned_value } }
#=> {"this"=>{"is"=>{"a"=>{"test"=>42}}}}