From: Ben Tilly Date: 2001-03-06T04:37:41+09:00 Subject: [ruby-talk:12052] Re: RCR: shortcut for instance variable initialization Dave Thomas wrote: > >r2d2@mao.acc.umu.se (Niklas Frykholm) writes: [...] > def fred(param1, param2, anotherparam) > @param1, @param2, @anotherparam = param1, param2, anotherparam > > ... > >has a couple of inherent problems. > [...] >I'd still like to find a way to do this without duplicating the names. > 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? 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? Cheers, Ben _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com