In C#, I can do this:
class Program
{
static void Main(string[] args)
{
List animals = new List();
anima
Building on the previous answer, is this how you might do it?
Second cut after clarification:
class Animal
def MakeNoise
raise NotImplementedError # I don't remember the exact error class
end
def Sleep
puts self.class.to_s + " is sleeping."
end
end
class Dog < Animal
def MakeNoise
return "Woof!"
end
end
class Cat < Animal
def MakeNoise
return "Meow!"
end
end
animals = [Dog.new, Cat.new]
animals.each {|a|
puts a.MakeNoise
a.Sleep
}
(I'll leave this as is, but "self.class.name" wins over ".to_s")