的值在我的散列的陣列使用#選擇要麼嵌套散列:在任一個散列或散列
test_multiple_hash = { test: { another_test: 123 } }
或散列的數組:
test_multiple_hash = { test: [{ another_test: 123 }, { another_test: 124 }] }
具有取出一個後值,我需要使用#選擇查找特定的嵌套哈希:
test_multiple_hash[:test].select { |s| s[:another_test] == 123 }
如果我的哈希只有一個散列,然後除非將單個散列轉換爲數組,否則不適合我的需要。
當散列中的某個鍵的值是單個散列或散列數組時,有沒有更好的方法通過鍵的值來查找對象?
什麼是'test_multiple_hash'? – sawa
酷,downvote沒有理由爲什麼? – Bodao
用更簡單的(嵌套散列)情況,你的預期結果是什麼? – sawa