From: Gavin Sinclair Date: 2003-01-12T22:11:34+09:00 Subject: Re: Instance vars as arguments to initialize()? On Sunday, January 12, 2003, 7:51:41 AM, Jim wrote: > In article , Jim Bob wrote: >> Wouldn't it be neater to be able to do "def initialize(@a, @b, >> @c);end" and be done with it? > Well, to follow up to myself, I would have to say that wouldn't make a > whole lot of sense. initialize would have to be some kind of "special" > method to act like that, much more so than it is now. > I've solved my "problem", such as it was, by writing a little Vim script > (using Ruby!) that, when called on a line like "A b c", builds a > class A > def initialize(b, c) > @b = b > @c = c > end > end > -type skeleton out of it. It was fun, too. You could try this too (untested): class Class def autoinit(*args) # Define "initialize" in terms of the symbols contained in *args end end class Example autoinit :a, :b, :c end Now, even though it's untested, I'm pretty sure it wouldn't work, cos I left a hole for you to fill :) (i.e. I started it and it became too hard) Gavin