"Weirich, James" <James.Weirich / FMR.COM> schrieb im Newsbeitrag
news:1C8557C418C561429998C1F8FBB283A728BA95 / MSGDALCLB2WIN.DMN1.FMR.COM...
> > > The following will work with arbitrary objects ...
> > >
> > >    obj.instance_eval("lambda { |v| @a = v }").call(value)
> >
> > Well, you can do it simpler, even if you *want* to use
> > instance_eval.  No need for a lambda:
> >
> > irb(main):001:0> class Foo
> > irb(main):002:1>  def test(obj)
> > irb(main):003:2>   instance_eval("@x=obj")
> > irb(main):004:2>  end
> > irb(main):005:1> end
>
> I stand corrected.  For some reason I thought that the value of 'obj'
> wouldn't be available inside of an instance_eval.

As far as I can see instance_eval just changes the value of 'self'.

> > > At this point you must be thinking:  "Why don't I just use
> > > instance_variable_set?"
> >
> > I'd love to see the answer to this question you'd suggest. :-))
>
> The question was meant to be rhetorical,

That's what I assumed.  I thought you might come up with a funny answer...
:-)

> although with the simplification
> the choice is less clear.

Yes, that's true.  And, as we have seen, instance_eval is more backward
compatible.

Kind regards

    robert