Skip to content

Instantly share code, notes, and snippets.

@novohispano
Last active December 14, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save novohispano/5035890 to your computer and use it in GitHub Desktop.
Save novohispano/5035890 to your computer and use it in GitHub Desktop.
module Fruit
class Apple
require 'time'
attr_accessor :variety
def initialize(variety = "Granny Smith")
@variety = variety
@remaining_slices = apple_size
@created_at = Time.now
end
def apple_size
rand(5..9)
end
def slice(slice = 1)
if slice <= @remaining_slices
@remaining_slices = @remaining_slices - slice
slice
else
@remaining_slices
end
end
def remaining_slices
@remaining_slices
end
def age
Time.now - created_at
end
def ripe?
age >= 10.0
end
def unripe?
age < 10.0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment