From: Wyss Clemens Date: 2001-08-14T13:00:37+09:00 Subject: [ruby-talk:19668] Re: Inheritance problem with PostgreSQL ext ension "def self.new" is being "executed" at the scope/context of class, so "self" is the class (i.e. MyPGconn). Recall, classes are objects, too. "def new" would create an instance method which is to be called on an instance (of the class). "def self.new" (alternatively "def MyPGconn.new") on the other hand declares a class mehtod. Hope this helps Regards Clemens > -----Urspr�ngliche Nachricht----- > Von: Hoss Firooznia [mailto:hoss@lodestone.org] > Gesendet am: Dienstag, 14. August 2001 05:48 > An: ruby-talk@ruby-lang.org > Betreff: [ruby-talk:19667] Re: Inheritance problem with PostgreSQL > extension > > Guy Decoux writes: > > > * the second is to consider that ::new not only make > memory allocation but > > also perform an initial setup, #initialize in this case > is used to do > > an extra setup. > > > > For postgres, this is the second choice and the initial > setup is the > > connection to the database. This mean that in your case > you must not > > redefine #initialize, but redefine ::new. > > > class MyPGconn < PGconn > > def self.new > [...] > > Thanks very much, Guy! This is tremendously helpful. > > One thing I don't quite understand, though, is why "self.new" > works when > just "new" doesn't. Isn't the "self" implicit? Shouldn't "def new" > override the definition of "new" in the ancestor class? > > By the way, I'm right in the middle of Thomas and Hunt's excellent > "Programming Ruby", so please feel free to ignore this > question if it's > something that should become self explanatory soon -- I'll RTFM. :-) > > Thanks, > - Hoss >