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.