Skip to content

Panda and Tiger Level #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions zoo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def full?
end
end


class Food

def ==(other)
Expand All @@ -65,13 +64,27 @@ class Tacos < Food; end
class Wildebeests < Food; end
class Zeebras < Food; end
class Bamboo < Food; end
class Bacon < Food; end

class Zookeeper
def feed(args={})
animal = args.fetch(:to)
food = args.fetch(:food)
panda = args.fetch(:to)
panda.eat(food)
animal.eat(food)
end

end

class Human
include Animal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check your browser's settings --- this looks like two tabs instead of 2 spaces.

(2 spaces are the preferred way in Ruby).


def acceptable_food
[Bacon.new, Tacos.new]
end
end

class FoodBarge
def food_for(animal)
animal.acceptable_food
end
end
23 changes: 23 additions & 0 deletions zoo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,26 @@ class Salad < Food; end
Zookeeper.new.feed(food: :zeebras, to: lion)
end
end

describe Human do
it "should like Bacon" do
Human.new.likes?(Bacon.new).should eq(true)
end
it "should like Tacos" do
Human.new.likes?(Tacos.new).should eq(true)
end
it "should not like bamboo" do
Human.new.likes?(Bamboo.new).should eq(false)
end
end

describe FoodBarge do
before(:each) do
@barge = FoodBarge.new
end
it "should bring food to pandas" do
panda = Panda.new
panda_food = panda.acceptable_food
@barge.food_for(panda).should eq(panda_food)
end
end