Thankyou caio

Hi caio,

   thanks for your valuble suggestion and it works
great.I have one another silly question

this is the code
class Song
def initialize(name, artist, duration)
  @name=name
  @artist=artist
  @duration=duration
end
def myclass_function
  puts "this is my first class"
end
def to_s
  puts "Song: #@name--#@artist (#@duration)"
end
end
class Karaokesong
def initialize(name, artist, duration, lyrics)
  super(name, artist, duration)
  @lyrics=lyrics
end
def to_s
  puts "Song: #@name--#@artist (#@duration)"
end
end

the following is the error

"myfirstprojectfile:16:in `initialize': wrong number
of arguments (3 for 0) (ArgumentError)"

the error is with super.

can you explain why it is.

Regards,
Navya.

···

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Navya Amerineni wrote:

Hi caio,

   thanks for your valuble suggestion and it works
great.I have one another silly question

this is the code
class Song
def initialize(name, artist, duration)
  @name=name
  @artist=artist
  @duration=duration
end
def myclass_function
  puts "this is my first class"
end
def to_s
  puts "Song: #@name--#@artist (#@duration)"
end
class Karaokesong
def initialize(name, artist, duration, lyrics)
  super(name, artist, duration)
  @lyrics=lyrics
end
def to_s
  puts "Song: #@name--#@artist (#@duration)"
end

the following is the error

"myfirstprojectfile:16:in `initialize': wrong number
of arguments (3 for 0) (ArgumentError)"

the error is with super.

can you explain why it is.

Change the following line:
    class Karaokesong
to:
    class Karaokesong < Song

That will make Karaokesong a subclass of Song. When you call super it will call Song's initialize method which takes 3 arguments. When it doesn't subclass Song, Karaokesong by default will subclass from Object. Object itself doesn't take any arguments in it's constructor.

HTH,

Zach