Thankyou caio

N

Navya Amerineni

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
 
Z

Zach Dennis

Navya said:
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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top