-
-
Save scottweisman/2782213 to your computer and use it in GitHub Desktop.
Revisions
-
JeffCohen created this gist
May 24, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ class VendingMachine # attr_accessor :money def initialize(number_of_cans) @cans = [] number_of_cans.times do @cans << 'Coke' end # => ['Coke', 'Coke', 'Coke', 'Coke'] @money = 0 end def empty? @cans.empty? # @capacity == 0 end def insert_coins(amount) @money = @money + amount end def push_button(brand) # @capacity = @capacity - 1 @cans.shift puts brand end def remove_money orig_amount = @money @money = 0 return orig_amount end end machine = VendingMachine.new(5) until machine.empty? machine.insert_coins(50) machine.push_button 'Coke' end puts machine.remove_money # => 250 puts machine.remove_money # => 0 # Coke # Coke # Coke # Coke # Coke # Extra credit