From 0d224a5fe97bd5de6d841adc3b7801f5197ea188 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Wed, 19 Aug 2015 14:49:52 +0200 Subject: [PATCH] fasterer: hash#fetch with block is faster hash#fetch with block is faster than hash#fetch with second parameter --- app/controllers/stats_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index d559686a..7369d456 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -448,7 +448,7 @@ class StatsController < ApplicationController end def three_month_avg(set, i) - (set.fetch(i,0) + set.fetch(i+1,0) + set.fetch(i+2,0)) / 3.0 + (set.fetch(i){ 0 } + set.fetch(i+1){ 0 } + set.fetch(i+2){ 0 }) / 3.0 end def set_three_month_avg(set,upper_bound)