Created
February 17, 2015 21:10
-
-
Save latortuga/93970669e7978b265d43 to your computer and use it in GitHub Desktop.
ecoding5
This file contains 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
$ ruby poodr.rb | |
poodr.rb:20:in `prepare_trip': undefined method `each' for nil:NilClass (NoMethodError) | |
from poodr.rb:6:in `block in prepare' | |
from poodr.rb:5:in `each' | |
from poodr.rb:5:in `prepare' | |
from poodr.rb:54:in `<main>' |
This file contains 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
class Trip | |
attr_reader :bicycles, :customers, :vehicle | |
def prepare(preparers) | |
preparers.each do |preparer| | |
preparer.prepare_trip(self) | |
end | |
end | |
end | |
# when every preparer is a Duck | |
# that responds to 'prepare trip' | |
class Mechanic | |
def initialize(bicycle) | |
@bicycle = bicycle | |
end | |
def prepare_trip(trip) | |
trip.bicycles.each do |bicycle| | |
prepare_bicycle(bicycle) | |
end | |
end | |
def bicycles | |
[1, 2] | |
end | |
def prepare_bicycle(bike) | |
p 'mech' | |
end | |
end | |
class TripCoordinator | |
def prepare_trip(trip) | |
buy_food(trip.customers) | |
end | |
# ... | |
end | |
class Driver | |
def prepare_trip(trip) | |
vehicle = trip.vehicle | |
gas_up(vehicle) | |
fill_water_tank(vehicle) | |
end | |
# ... | |
end | |
m = Mechanic.new(2) | |
t = Trip.new | |
t.prepare([m]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment