From: Brian Candler Date: 2003-07-02T22:50:30+09:00 Subject: Re: anonymous classes On Wed, Jul 02, 2003 at 05:36:21PM +0900, Dominik Werder wrote: > > What you've written is called a "singleton class". I wrote this a while: > > > > http://www.rubygarden.org/ruby?SingletonTutorial > > > it is very helpful for me too :) > > One question referring to > "A neat solution then is to create a singleton class for each POP3 > connection as it arrives: " > How much memory does this technique consume? Are the new methods created > for each individual instance? Or just something like a lookup table? All that happens is that a new proxy class is added to the object, which points at the module which you #extended it with. It certainly doesn't copy all the methods. You can prove this easily enough, by modifying the module *after* you have done extend: module A end a = "hello" a.extend A b = "world" b.extend A module A def foo puts "it works" end end a.foo #=> "it works" b.foo #=> "it works" You can see that the two objects share the same module implementation. Regards, Brian.