2010-08-25 64 views

回答

2

像這樣應該工作:

hash.values.collect{|v| v[0]} 

實施例:

irb(main):001:0> hash = { 1 => { 0 => 'apple', 1 => 'tree' }, 
    2 => { 0 => 'foo', 1 => 'bar' }} 
=> {1=>{0=>"apple", 1=>"tree"}, 2=>{0=>"foo", 1=>"bar"}} 
irb(main):002:0> hash.values.collect{|value| value[0]} 
=> ["apple", "foo"] 
+0

未定義的方法'值爲#<陣列:0x450d120> .... 我有散列內散列雖然...「test」=> {「1」=> {「0」=>「testing」.... – user385948 2010-08-25 14:45:29

+0

我看到它在我的控制檯中工作...但事情是我拉一個參數關閉一個表,將其轉換爲一個數組,然後排序成一個散列 – user385948 2010-08-25 14:49:46

相關問題