Я думаю, что следующее поможет вам начать:
class Dog
def speak
puts "woof"
end
end
class Cat
def speak
puts "meow"
end
end
class PetLover
attr_accessor :species
def initialize
@species = [Dog, Cat]
end
def random_animal
@species[rand(@species.size)].new
end
def animals(n)
ary = []
n.times do
ary << random_animal
end
ary
end
end
pl = PetLover.new
p pl.animals(10)