Permalink
Browse files

Refactor into modules

  • Loading branch information...
1 parent 57f536f commit e81880ad3fa7479cd592428e2858f5376ed55e4c @jwo jwo committed Apr 26, 2012
Showing with 6 additions and 16 deletions.
  1. +6 −7 zoo.rb
  2. +0 −9 zoo_spec.rb
View
13 zoo.rb
@@ -1,12 +1,9 @@
#Zoo
-class Animal
-
- def initialize
- @meals = 0
- end
+module Animal
def eat(food)
+ @meals ||= 0
if likes?(food)
@meals += 1
true
@@ -30,7 +27,8 @@ def full?
end
-class Panda < Animal
+class Panda
+ include Animal
def acceptable_food
[:bamboo]
@@ -42,7 +40,8 @@ def full?
end
-class Lion < Animal
+class Lion
+ include Animal
def acceptable_food
[:wildebeests, :zeebras]
View
@@ -1,15 +1,6 @@
# Zoo spec file
require "./zoo"
-describe Animal do
- it "should not raise an exception when we try to like" do
- expect {
- Animal.new.likes?(:bacon)
- }.to_not raise_error
- end
-
-end
-
describe Panda do
it "should like bamboo" do

0 comments on commit e81880a

Please sign in to comment.