Skip to content

Commit

Permalink
p.133 rewrite "calculate_outstanding" with inject function.
Browse files Browse the repository at this point in the history
  • Loading branch information
kono committed May 11, 2010
1 parent 693fe14 commit 9003665
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions chapter6/Extract_Method.rb
Expand Up @@ -38,9 +38,5 @@ def print_details(outstanding)
end

def calculate_outstanding
outstanding = 0.0
@orders.each do |order|
outstanding += order.amount
end
outstanding
@orders.inject(0.0){|result, order| result + order.amount }
end

0 comments on commit 9003665

Please sign in to comment.