我有以下课程 class Animal def move "I can move" endendclass Bird Animal def move super + " by flying" endendclass Penguin Bird def move #How can I call Animal move here "I can move"+ ' by swimming' endend 如何在Penguin中调用Anim
class Animal
def move
"I can move"
end
end
class Bird < Animal
def move
super + " by flying"
end
end
class Penguin < Bird
def move
#How can I call Animal move here
"I can move"+ ' by swimming'
end
end
如何在Penguin中调用Animal的移动方法?我不能使用super.super.move.有什么选择?
谢谢
你可以获得Animal的move实例方法,将它绑定到self,然后调用它:class Penguin < Bird
def move
m = Animal.instance_method(:move).bind(self)
m.call
end
end
