2012-09-04 118 views

回答

0

你沒有給出太多的上下文(你正在使用的數據庫寶石等)。

不過,我能想到幾種方法把我的頭頂部:

reuslts.to_a # might not work (depends on how you're accessing the db) 

a = [] 
results.each { |r| a << r } # will definitely work assuming `each` is defined 

記住,該#query方法可能會返回一個很好的理由發電機。將結果轉換爲數組將是一個毫無意義的內存消耗(並且耗時)。使用#each絕對是可取的,因爲它會更有效率。