From: Justin Bailey Date: 2006-05-09T05:38:33+09:00 Subject: Re: Question about instance_eval ------=_Part_42884_21137293.1147120709035 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline No. Define method missing to dispatch calls to "foo" to the accessor, and change your block just a little bit. E.g. class IETest def method_misssing(sym, *args, &blk) # dispatches any methods missing to "assignment" version of method. self.__send__(sym + "=3D", *args, &blk) end end t =3D IETest.new t.instance_eval { foo 'foo' } # notice lack of assignment operator puts t.foo On 5/8/06, Pat Maddox wrote: > > I'm trying to use instance_eval in a project I'm doing, and I > extracted a very simple example: > > class IETest > attr_accessor :foo > end > > t =3D IETest.new > t.instance_eval { self.foo =3D 'foo' } > puts t.foo > > This works as expected. However if I do > t.instance_eval { foo =3D 'foo' } > > then t.foo =3D> nil > > I also know that t.instance_eval { @foo =3D> 'foo' } would work in this > case. However, I'm trying to set a Rails attribute, so I have to go > through the method accessor. Is there any way that I can make this > work with just { foo =3D 'foo' } instead of { self.foo =3D 'foo' } ? > > Pat > > ------=_Part_42884_21137293.1147120709035--