From: "trans. (T. Onoma)" Date: 2004-09-30T01:18:47+09:00 Subject: Re: Best name for "this method" ? On Wednesday 29 September 2004 05:19 am, Robert Klemme wrote: > I prefer #new because it emphasizes the factoryness of a Class instance. > Class() doesn't help you in cases like these: > > class SomeFactory > def initialize(cl) > @cl = cl > end > > def create() @cl.new end > def discard(obj) end > end I don't follow. Help you do what? It would still instantiate the factory. (IMHO) factories are better as module functions, anyway. So you could do something like: class SomeFactory def self.set(cl) @@cl = cl end def self.new @@cl.new end end SomeFactory.set(String) str = SomeFactory() If one so desired. Besides, all methods that return a new value are "factories". That;s actually the main point --why () is better then []. > Also, methods Integer() and such are defined in Kernel. Having such a > method as a wrapper for C.new in Kernel for every class would clutter > Kernel unnecessarily and introduce unnecessary dependencies. I try to > stick to the rule of thumb to change base classes as minimal as possible. > That way code stays maintainable and the likeliness of imcompatibilities > between different classes that change Kernel and the like decreases. Sure. I'd rather not clutter up Kernel either. I think its already got too many methods (why all those string related methods, for instance?) But in this case it doesn't really bother me, especially if a missing_method takes care of it. It might be interesting if () were a "method dispatcher" method itself, then it could be defined/redefined like [] is. But don't quote me on that, for the moment it's just a passing thought ;) T.