Created
April 9, 2016 18:50
-
-
Save graemeboy/4b9e4bc396cfa514438f6ec30e75afaa to your computer and use it in GitHub Desktop.
Examples of smaller classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassicRentalPrice | |
attr_reader :days_rented | |
def initialize(days_rented) | |
@days_rented = days_rented | |
end | |
def amount | |
2 * days_rented | |
end | |
end | |
class NewRentalPrice | |
attr_reader :days_rented | |
def initialize(days_rented) | |
@days_rented = days_rented | |
end | |
def amount | |
3 * days_rented | |
end | |
end | |
class DocumentaryRentalPrice | |
attr_reader :days_rented | |
def initialize(days_rented) | |
@days_rented = days_rented | |
end | |
def amount | |
if on_special? | |
0 | |
else | |
1 * days_rented | |
end | |
end | |
def on_special? | |
Time.now.wday == 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment