Good day everyone. I am writing a simple ruby code but it doesn't print on the screen I am using ruby 2.2.2 and my IDE is Rubymine 7.Thanks in advance.Here is the code;
class Animal
attr_accessor :name, :colour
def initialize(name,colour)
@name = name
@colour = colour
end
def to_s
"Name#{@name} Colour #{@colour}"
end
end
class Cheetah < Animal
attr_reader :speed
def initialize(name,colour,speed)
@speed = speed
super (name,colour)
end
def to_s
return super + "Speed#{@speed}kph"
end
end
class Zoo < Animal
def initialize
@animals = []
end
def add_animals(animal)
@animals << animal
end
def my_animals
cage = ""
@animal.each do|call|
cage += call.to_s
end
end
end
5.times do|count|
Zoo.add_animals(MyAnimal.new("Cheetah#{count}","yello and black spots"))
end
puts "#{Zoo.my_animals}"
My_cheetah = Cheetah.new("Cheetah","yello and black spots",180)
puts "#{My_cheetah.to_s}"
Zoo.my_animalsyou're referencing@animal(i.e. not pluralized), also in that same method, you're building up a string (cage), but you never return it (the return value of a call to.eachis nil).eachisself, as specified in the documentation ofeach.