Skip to content

Instantly share code, notes, and snippets.

@idlehands
Created October 15, 2012 20:09
Show Gist options
  • Save idlehands/3895022 to your computer and use it in GitHub Desktop.
Save idlehands/3895022 to your computer and use it in GitHub Desktop.
instance fun
class BakingSheet
attr_accessor :cookies_on_the_sheet
def initialize
@cookies_on_the_sheet = []
end
def add_cookies(cookies)
@cookies_on_the_sheet << cookies
end
def bake
@cookies_on_the_sheet.each do |cookies|
cookies.bake
end
end
def to_s
puts "There are #{my_batch_of_cookies.num_of_cookies} cookies on your #{self.class}."
end
end
class Cookie
end
class ChocChip < Cookie
attr_reader :num_of_cookies
def initialize(num_of_cookies)
@num_of_cookies = num_of_cookies
@time_baked = 0
end
def bake
@time_baked += 1
end
# def to_s
# puts "You just made #{@num_of_cookies} doughy #{self.class} cookies!"
# end
end
# design
##################################
# procedure
my_batch_of_cookies = ChocChip.new(6)
# my_batch_of_cookies = ChocChip.new(4)
my_baking_sheet = BakingSheet.new
my_baking_sheet.add_cookies(my_batch_of_cookies)
my_baking_sheet.bake
my_baking_sheet.add_cookies(my_batch_of_cookies)
puts my_baking_sheet.cookies_on_the_sheet.inspect
=begin
STEPS:
[x] 1) Make cookies
[] 2) Put cookies on baking sheet
[] 3) Put baking sheet into oven
[] 4) Wait for some time
[] 5) Are cookies done?
[] 6) If no, keep waiting
If yes, remove cookies from oven
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment