class Animal
attr_accessor :name
def initialize(name)
@name = name
end
def speak
"#{ name } is speaking!"
end
end
class Dog < Animal
def speak
"#{ name } is barking!"
end
end
class Cat < Animal
end
fido = Dog.new('fido')
puts fido.name
puts fido.speak
kitty = Cat.new('kitty')
puts kitty.name
puts kitty.speak
puts Dog.ancestors
produce
fido
fido is barking!
kitty
kitty is speaking!
Dog
Animal
Object
Kernel
BasicObject