From: "David A. Black" Date: 2004-12-15T22:06:03+09:00 Subject: Re: initialize always Hi -- On Wed, 15 Dec 2004, Robert Klemme wrote: > Finally today I found a sheet of paper while cleaning my desk. (It's good > to do that once in a while. :-)) > > It hadn't made it to an RCR though. The suggestion would have been this: > if a Module defines method initialize without an argument list then > implicitely change that to be initialise(*a,&b) and implicitely add super > as first line in the method: Thus > > module Foo > def initialize > @bar = 0 > end > end > > becomes > > module Foo > def initialize(*a,&b) > super > @bar = 0 > end > end > > Note: identifiers for arguments and block may have to be generated to be > unique. > > All other cases (i.e. combinations of with / without argument list and > with / without occurrence of "super" in the body of this method) should > remain unchanged, because they would cause too much hassle. > > Pro: this change allows for easy initialization of instance variables > needed by modules even if there are multiple modules included: > > class Base > def initialize(x) > @x = x > end > end > > class Test < Base > include Foo > include Bar > > def initialize(a, b) > super(a) > @b = b > end > end > > What do others think? My initial reaction is that it's too magic for my taste... too much written in "invisible ink". If I write: def meth; ...; end then I want it to fail if it's called with arguments. But I'm also not understanding the 'pro' point very thoroughly, or maybe I've just never had this problem. I think I'm just being thick, but can you explain a little more how/when/why this would be useful? David -- David A. Black dblack@wobblini.net