Skip to content

Instantly share code, notes, and snippets.

@graemeboy
Created April 9, 2016 18:50
Show Gist options
  • Save graemeboy/4b9e4bc396cfa514438f6ec30e75afaa to your computer and use it in GitHub Desktop.
Save graemeboy/4b9e4bc396cfa514438f6ec30e75afaa to your computer and use it in GitHub Desktop.
Examples of smaller classes
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