[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

inheritance, calling super / initialize

Patrick Gundlach

10/22/2003 7:42:00 PM

Dear Ruby Hackers,

another newbee question:

--------------------------------------------------
class A
def initialize (a,b)
# do something complicated:
puts a + b
end
end

class B < A
def initialize
super.new ("Hello", "world") # line 12
end
end

B.new
--------------------------------------------------

Gives me
-:12:in `initialize': wrong # of arguments(0 for 2) (ArgumentError)
from -:12:in `initialize'
from -:16:in `new'
from -:16


I can do something like this:

--------------------------------------------------
class B < A
alias :supernew :initialize
def initialize
supernew ("Hello", "world")
end
end
--------------------------------------------------


But is this the way to go? Calling the initialize method for a super
class is common in OOP, isn't it?


Patrick
--
You are your own rainbow!
1 Answer

Lyle Johnson

10/22/2003 8:38:00 PM

0

Patrick Gundlach wrote:

> class B < A
> def initialize
> super.new ("Hello", "world") # line 12
> end
> end

You were close ;) Try this instead:

class B < A
def initialize
super("Hello", "world")
end
end

Hope this helps,

Lyle