今天正式开始看 Programming Ruby 中文版,第 66 页按书中代码输入,结果运行提示错误,不知道何原因,很初级了,想不明白。
air-mxtekiMacBook-721:PR 721-mx$ ruby pr63.rb
pr63.rb:2:in `initialize': wrong number of arguments (4 for 3) (ArgumentError)
from pr63.rb:21:in `new'
from pr63.rb:21:in `<main>'
class Song
def initialize(name,artist,duration)
@name =name
@artist =artist
@duration = duration
end
def to_s
"Song: #@name #@artist(#duration)"
end
end
class KaraokSong < Song
def initailize(name,artist,duration,lyrics)
super(name,artist,duration)
@lyrics=lyrics
end
end
song = KaraokSong.new("adsf","dsaf",34234,"234")
song.to_s