From: Christoph Rippel Date: 2001-03-06T05:57:27+09:00 Subject: [ruby-talk:12059] Re: RCR: shortcut for instance variable initialization > From: Ben Tilly [mailto:ben_tilly@hotmail.com] [...] > Well if not duplicating the names is the point, you could > always make the temporary variables have names that have > nothing to do with the variables you are actually setting. > > /duck > > OK, ok, on to a more serious note. I don't have a good > suggested syntax, but how about we generalize the desire > for a second and think about where that leads? If you > have written your attr methods, your temporary variables > actually all correspond pretty closely to methods that > you have already. For instance: > > attr_accessor :foo > > will have created methods foo and foo= for public access to > @foo. > > Am I right that you would be happy if you could just call > foo= directly? As usual, you make one of the most interesting comments (for my taste;-). Actually there is a little problem if have something like class Whatever def will_be_rounded=(number) raise 'Not a number' unless kind_of? Numeric @will_be_number = number.round end def initialize(will_be_rounded@) ... end attr_accessor :will_be_rounded end does a call to initialize invoke ``@will_be_rounded='' or```will_be_rounded=''? > I can't think of what it should look like, but there might > be a number of uses for a syntax that allows you to easily > preprocess your argument list in a variety of ways. (One > idea bubbling in my brain is named function parameters.) > > So can anyone think of more uses for the idea or (far more > importantly) what a reasonable syntax might be? I am pretty neutral about this RCR but one way might be the introduction of additional ``#initialize's'' - maybe something like def initialized(initialize_me; dont_initialize_me) ... end but you still have the problem about the ambiguity of the ``initialize_me='' invocation. Ps. I sometimes wonder if Ruby could have done without variables at all (I believe this) and only use attributes but this is a different matter. [...] Christoph