Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 99b3fda

Browse files
committed
Page 43: Replacing the Conditional Logic on Price Code with Polymorphism (added RegularPrice.charge and implemented in Movie.charge)
1 parent 8d64bab commit 99b3fda

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

‎chapter_1.rb‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ def charge(days_rented)
2323
result = 0
2424
case price_code
2525
when Movie::REGULAR
26-
result += 2
27-
result += (days_rented - 2) * 1.5 if days_rented > 2
26+
return @price.charge(days_rented)
2827
when Movie::NEW_RELEASE
2928
result += days_rented * 3
3029
when Movie::CHILDRENS
@@ -40,6 +39,11 @@ def frequent_renter_points(days_rented)
4039
end
4140

4241
class RegularPrice
42+
def charge(days_rented)
43+
result = 2
44+
result += (days_rented - 2) * 1.5 if days_rented > 2
45+
result
46+
end
4347
end
4448

4549
class NewReleasePrice

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /