From: dblack@... Date: 2006-05-23T06:03:41+09:00 Subject: Re: initializing instance variables in a module ---2049402039-269613951-1148331779=:7144 Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-269613951-1148331779=:7144" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---2049402039-269613951-1148331779=:7144 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Tue, 23 May 2006, Simon Kr=F6ger wrote: > Francis Cianfrocca schrieb: >> You still have to call it every time you use the variable. >> > > Do you realy need to use the variable directly? > My scripts tend to have very little use of '@'. > > module Foo > def bar(key) > @myvar ||=3D Hash.new {|k,v| k[v] =3D []} > @myvar[key] > end > end > > class Test > include Foo > end > > t =3D Test.new > t.bar('baz') << 'eeek' > p t.bar('baz') > > > I didn't followed the whole thread so please ignore me > if this was suggested before. It was -- that, or a close variant, was what I don't understand the non-usefulness of, but although I've read the thread I think there's some level of complexity I haven't caught sight of. David --=20 David A. Black (dblack@wobblini.net) * Ruby Power and Light, LLC (http://www.rubypowerandlight.com) > Ruby and Rails consultancy and training * Author of "Ruby for Rails" from Manning Publications! > http://www.manning.com/black ---2049402039-269613951-1148331779=:7144-- ---2049402039-269613951-1148331779=:7144--