小编use*_*335的帖子

Ruby On Rails:将字符串中的路径转换为递归哈希

有人能建议我这样做的方法吗?(所有都在主题:D)

我想要的是使用"路径"并将其转换为子键,

例如:我有那个参数:path ="earth/animal/human/men/young /"value ="martin"我希望:

  `Global_hash = { earth => { human => { men => { young => "martin"
                                                }
                                       }
                            }
                 }`
Run Code Online (Sandbox Code Playgroud)

path ="earth/animal/human/men/old /"value ="John",我想:

 Global_hash = { earth => { human => { men => { young => "martin",
                                                old   =>  "John" 
                                         }
                                }
                     }
          }
Run Code Online (Sandbox Code Playgroud)

加上另一个

path ="earth/animal/human/women/old /"value ="Eve",我想:

`Global_hash = { earth => { human => { men   => { young => "martin",
                                                  old      =>  "John"
                                                },
                                       women => { old => …
Run Code Online (Sandbox Code Playgroud)

ruby string hash ruby-on-rails path

2
推荐指数
1
解决办法
966
查看次数

标签 统计

hash ×1

path ×1

ruby ×1

ruby-on-rails ×1

string ×1