LAMBEAU Bernard
1/8/2009 2:21:00 PM
obj.instance_eval {| | block } => obj
I don't interpret it that way: it only states that self is obj inside
the block. The documentation says nothing about block arguments.
I would like something like this:
obj.instance_eval {| who| block } => obj
where who ==self == obj.
blambeau
On Thu, Jan 8, 2009 at 3:15 PM, Jan-Erik R. <badboy@heartofgold.co.cc> wrote:
> LAMBEAU Bernard schrieb:
>>
>> Ruby's documentation of instance_eval shows the "signature" of
>> instance_eval as:
>>
>> obj.instance_eval {| | block } => obj
>>
>> I assume that the block should not take any argument. However, if I
>> write the following code:
>>
>> class A
>> def sayhello(who)
>> puts "hello #{who}: #{object_id}"
>> end
>> end
>>
>> A.new.instance_eval do |who|
>> sayhello("me")
>> who.sayhello("who")
>> end
>>
>> it prints "hello me: -605850598" then "hello who: -605850598"
>>
>> Is is guaranteed to work??
>>
>> blambeau
>>
>
> should be, because it's documented. Not in the code-example but in the text:
> In order to set the context, the variable self is set to obj while the
> code is executing, giving the code access to obj's instance variables.
>
>