Skip to content

Commit

Permalink
p.133-134 complexed outstanding(extract method "calculate_outstanding").
Browse files Browse the repository at this point in the history
  • Loading branch information
kono committed May 11, 2010
1 parent 3a1facb commit a491eca
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions chapter6/Extract_Method.rb
Expand Up @@ -20,12 +20,7 @@ def print_owing(previous_amount)
outstanding = previous_amount * 1.2

print_banner

# 勘定を計算(calculate outstanding)
@orders.each do |order|
outstanding += order.amount
end

outstanding = calculate_outstanding(outstanding)
print_details outstanding
end

Expand All @@ -41,5 +36,8 @@ def print_details(outstanding)
puts "name: #{@name}"
puts "amount: #{outstanding}"
end


def calculate_outstanding(initial_value)
@orders.inject(initial_value){|result, order| result + order.amount}
end
end

0 comments on commit a491eca

Please sign in to comment.