Last active
December 14, 2015 05:29
-
-
Save novohispano/5035890 to your computer and use it in GitHub Desktop.
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
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