Rails Average - 折扣0值

时间:2013-04-05 16:33:57

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

我创建了数组,我需要找到平均值如下:

total_rating = []
#add numbers to total_rating
average = total_rating.inject(:+).to_f / total_rating.size

如何从此平均值计算中删除0值?我不希望在平均计算中计算0行。

1 个答案:

答案 0 :(得分:1)

total_rating.reject(&:zero?)