参见英文答案 >
What is the most ruby-ish way of accessing nested hash values at arbitrary depths? 4个
> How to avoid NoMethodError for missing elements in nested hashes,without repeated nil checks?16个
在Ruby中,我想做这样的事情,
> How to avoid NoMethodError for missing elements in nested hashes,without repeated nil checks?16个
在Ruby中,我想做这样的事情,
我有一个像这样构建的哈希哈希.
h = {1 => {2 => {3 => "three"}},'a' => { 'b' => { 'c' => "basd"}}} => {"a"=>{"b"=>{"c"=>"basd"}},1=>{2=>{3=>"three"}}}@H_404_7@如果我有一个像这样的值的数组.
a = [1,2,3]@H_404_7@我想有一个方法,它将使用数组值索引我的哈希中的嵌套键,并返回最后一个键指向的值(由前面的数组/键指导)
例如.getHashValue([1,3]) should return "three" => h[1][2][3]@H_404_7@如果a = [‘a’,’b’,’c’]则返回值应为basd.
怎么做到这一点?