From: David Alan Black Date: 2001-03-06T01:51:29+09:00 Subject: [ruby-talk:12042] Re: RCR: shortcut for instance variable initialization On Tue, 6 Mar 2001, Dave Thomas wrote: > r2d2@mao.acc.umu.se (Niklas Frykholm) writes: > > > > class Msg > > > def initialize(@name, @type, @txt) > > > end > > > end > > > > I do not like the idea. Adding magic just to save typing is only a > > good idea if the magic is beautiful. This magic is not. > > I agree it isn't pretty, and that the idea is probably dead. But let > me explain my motivation. [...] > I'd still like to find a way to do this without duplicating the names. I have what is probably a weird idea, but anyway, have a look: class Msg def initialize(name@, type@, txt@) # Here, the variables would be available *without* the '@' # e.g., "puts name" # and the assignments "@name = name", etc., would be automatic end end The point would be to trigger the assignment, but without using exactly the same name as the instance variables themselves. (I do find (@name, @type, @txt) confusing.) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav