def foo(val)
{
one: [["one1", "1"]],
two: [
["two1", "1"],
["two2", "2"]],
}[val]
end
我想从“1”中检索“two1”,我该怎么做?
注意:我想做[:two] [“1”]
答案 0 :(得分:2)
def foo(v1, v2)
hsh = {
'one' => [["one1", "1"]],
'two' => [ ["two1", "1"],
["two2", "2"] ],
}
hsh[v1].select{|i| i[0] == (v1 + v2) && v2 == i[1] }.first.first
end