翔如菲菲

其实天很蓝,阴云总会散;其实海不宽,此岸连彼岸.

导航

Ruby的super关键字:增强父类方法

#增强父类方法:super关键字
class Person
  def talk(name)
    print "my name is #{name}"
  end
end

class Student<Person
  def talk(name)
    super
    print " and i am a student."
  end
end

puts "Person class:"
p=Person.new
p.talk("Jeriffe"#my name is Jeriffe

puts "\nStudent class:"
s=Student.new
s.talk("Summer")  #my name is Summer and i am a student.

posted on 2012-01-31 14:25  翔如飞飞  阅读(350)  评论(0编辑  收藏  举报