Commits

Bożydar Sobczak committed 44548aa

lab3 added

  • Participants
  • Parent commits 1605707

Comments (0)

Files changed (1)

+class Food
+  attr_accessor :color
+  
+  def vomit
+    "vomitting in #{color}"
+  end
+end
+
+class Animal
+  
+  attr_accessor :edible
+  
+  def can_eat?(food)
+    edible.include?(food.class)
+  end
+  
+  def eat(food)
+    puts "start eating"
+    if can_eat?(food)
+      puts "mniam... good #{food.class}"
+    else
+      puts "bleee.... awful #{food.class}." + food.vomit
+    end
+  end
+end
+
+class Carrot < Food
+  def initialize
+    self.color = "orange"
+    puts "color: #{color}"
+  end
+end
+
+class Potato < Food
+  def initialize
+    self.color = "yellow"
+  end
+end
+
+class BlueCheese < Food
+  def initialize
+    self.color = "green"
+    puts "color: #{color}"
+  end
+end
+  
+  
+class Pig < Animal
+  
+  def initialize
+    super
+    self.edible = [Carrot, Potato]
+  end
+  
+end
+
+pig = Pig.new
+pig.eat(Carrot.new)
+pig.eat(BlueCheese.new)