On Wed, May 02, 2001 at 07:16:58AM +0900, Yukihiro Matsumoto wrote:
> |>   class DbConnection < Mysql
> |>     def DbConnection.new(*args)
> |>       conn = super(*args)
> |>       conn.initialize(*args)
> |>       return conn
> |>     end
> |>     def initialize(host, db, user, pass)
> |>       print "In Constructor\n"
> |>     end
> |>   end
> |>   con = DbConnection.new("localhost","rubytest","root", "") 
> |
> |Hi
> |
> |This works, thank you!
> |
> |But it has to be just "initialize" instead of "conn.initialize" - otherwise
> |ruby complaing about calling an private function unsing an expicit receiver.

> Oops, I forgot that initialize was private method.
>   conn.__send__(:initialize, *args)
> or
>   conn.instance_eval{initialize(*args)}
> 
> would do.  Just "initialize" would invoke the method of the
> DbConnection class.
Why?

Even if this is the case normally (this would make sense, given that all
methods are what is kind "virtual" in c++), this seems to be exactly the
place where the Mysql-Constructor fails. Otherwise it wouldn't be necessary
to overload "new", but I could just overload "initialize".)

This makes me believe, that the following should work:

class DbConnection < Mysql
	def DbConnection.new(*args)
		super(*args)
		initialize(*args)
	end
	
	def initialize(host, db, user, pass)
		super(*args)
		print "In Constructor\n"
	end
end

Or am I missing something?

greetings, Florian Pflug