Skip to content

Instantly share code, notes, and snippets.

@kazuhisa
Created March 19, 2013 11:30
Show Gist options
  • Select an option

  • Save kazuhisa/5195394 to your computer and use it in GitHub Desktop.

Select an option

Save kazuhisa/5195394 to your computer and use it in GitHub Desktop.
sample
class Rental
attr_reader :movie, :days_rented
def initialize(movie, days_rented)
@movie, @days_rented = movie, days_rented
end
def charge
result = 0
case movie.price_code
when Movie::REGULAR
result += 2
result += (days_rented - 2) * 1.5 if days_rented > 2
when Movie::NEW_RELEASE
result += days_rented * 3
when Movie::CHILDRENS
result += 1.5
result += (days_rented - 3) * 1.5 if days_rented > 3
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment