-4
def foo(val)
{
  one: [["one1", "1"]],
  two: [
         ["two1", "1"],
         ["two2", "2"]],
}[val]
end

我想从“1”中检索“two1”,我该怎么做?

注意:我想做 [:two]["1"]

4

1 回答 1

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
于 2013-07-12T05:51:44.767 回答