Skip to content

Commit

Permalink
p.51 use "inject" to calculate frequent_renter_points
Browse files Browse the repository at this point in the history
  • Loading branch information
kono committed Apr 11, 2010
1 parent 398773d commit 7e17d68
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions chapter1/Customer.rb
Expand Up @@ -18,14 +18,12 @@ def statement
frequent_renter_points = 0
@result = "Rental Record for #{@name}\n"
@rentals.each do |element|
frequent_renter_points += element.frequent_renter_points

# このレンタル料金を表示
@result += "\t" + element.movie.title + "\t" + element.charge.to_s + "\n"
end
# フッター行を追加
@result += "Amount owed is #{total_charge}\n"
@result += "You earned #{frequent_renter_points} frequent renter points"
@result += "You earned #{total_frequent_renter_points} frequent renter points"
print @result
end

Expand All @@ -35,4 +33,7 @@ def total_charge
@rentals.inject(0){|sum, rental| sum + rental.charge}
end

def total_frequent_renter_points
@rentals.inject(0){|sum, rental| sum + rental.frequent_renter_points}
end
end

0 comments on commit 7e17d68

Please sign in to comment.