的值在我的散列的阵列使用#选择要么嵌套散列:在任一个散列或散列
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