2012-09-04 195 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绝对是可取的,因为它会更有效率。