Le samedi 17 mars 2007 18:50, Corey K. a Ã©critÂ :
I am trying to figure out how inheritance works using the super method.
With the sample code below i get the error that i dont have enough
arguments for the constructor i dont understand why i am getting that
I have read the questions you posted the last few days, and I would like
give you a general counsel. It looks like you don’t take care of the
when an exception is raised. Though, the informations displayed when an
occurs are very useful, and if you had paid attention to it, you would
found your error immediatly.
For your particular problem, you can see this output :
initialize': wrong number of arguments (1 for 2) (ArgumentError) from /tmp/animal.rb:13:ininitialize’
from /tmp/animal.rb:21:in `new’
If you don’t already know, the first line means that at line 13 (line 13
super(color)) a method was called with 1 argument instead of 2. This is
sufficient to start tracking down the error. The other lines represents
call stack, ie the “path” which was followed to reach the exception.
And if there is an exception you don’t understand, or that doesn’t help
then join it with your code in your next message.