From b9336f10863f4d268d79c7b0ebff7c728c152be1 Mon Sep 17 00:00:00 2001 From: Hiroshi Kono Date: Sun, 30 May 2010 11:34:21 +0900 Subject: [PATCH] p.160 salary_total;after refactoring. --- chapter6/Replace_Loop_with_Collection_Closure_Method.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/chapter6/Replace_Loop_with_Collection_Closure_Method.rb b/chapter6/Replace_Loop_with_Collection_Closure_Method.rb index abfd8b9..b095319 100644 --- a/chapter6/Replace_Loop_with_Collection_Closure_Method.rb +++ b/chapter6/Replace_Loop_with_Collection_Closure_Method.rb @@ -31,7 +31,5 @@ def managerOffices_proc(employees) end def salary_total(employees) - total = 0 - employees.each{|e| total += e.salary} - total + total = employees.inject(0){|sum, e| sum + e.salary} end