Marnen Laibow-Koser wrote:
> Aldric Giacomoni wrote:
>> 
>> def proc_with_enclosing_scope
>>   name = "Ruby"
>>   lambda { puts name }
>> end
>> 
>> the_proc = proc_with_enclosing_scope
>> the_proc.call
>> 
>> name = "Java"
>> the_proc.call
>> 
>>  why would changing the name outside the
>> method make a difference in the first place?
> 
> It doesn't.  Did you try the code?  Both instances of the_proc.call 
> return "Ruby".  I assume the 'name="Java"' line is just there to point 
> out that it's not the same variable.

I did try the code. I was confused by what Dave Thomas was trying to 
point out, it seemed obvious to me that the code would return Ruby both 
times.

>> 
>> So.... When the_proc gets assigned the ... Value of the method
>> running... (?) What does it get assigned?
> 
>>> proc_with_enclosing_scope.class
> => Proc
> 
>> 
>> And lastly.. I know that "proc" exists, too. What is the difference /
>> what does it do?
> 
> lambda {} is nearly equivalent to Proc.new {}.  See 
> http://ruby-doc.org/core/classes/Kernel.html#M005945 .

Alright.. I had read that before and hadn't made too much sense of it, 
but maybe I'm just thinking too hard.
So.. Proc and Lambda are .. Pretty much the same thing, according to 
Ruby.

So they really are "bits of code with its own environment" ?
When is that useful? Maybe I need to watch Dave Thomas' presentation 
again.. :)

Thanks, Marnen.
-- 
Posted via http://www.ruby-forum.com/.