Hi --

On Wed, 1 Mar 2006, Robert Klemme wrote:

> dblack / wobblini.net wrote:
>> Hi --
>>
>> On Tue, 28 Feb 2006, Robert Klemme wrote:
>>
>>> rubyrus wrote:
>>>> Can anybody help me here, TIA!!
>>>>
>>>> This is the code.  I expect to see the string "Afterward:turkey",
>>>> but why am I getting "Afterward:camel"?  |animal| parameter in a
>>>> block should be temporary inside the block, right??
>>>
>>> No, it isn't because it was defined outside the block.  It's used in
>>> cases like
>>>
>>> count = 0
>>> arr.each { count += 1 }
>>> puts "count=#{count}"
>>>
>>> If you want to keep it local you must not define it in the
>>> surrounding scope.
>>
>> I think that's a different thing, though, from the parameter
>> semantics.  As I understand it, in 2.0 things would work like this:
>
> Is there a difference with regard to scope between
>
> (1..10).each {|foo| }
>
> and
>
> (1..10).each { foo = 1 }
>
> ?  I think in both cases foo is limited to the block:

I guess I had the impression that what puzzled the OP was that using a
variable as a block parameter (as opposed to just using it in the
block) was trampling the outer variable.  Anyway, as you say, all
perspectives have been accounted for (many times, counting the
archives :-)


David

-- 
David A. Black (dblack / wobblini.net)
Ruby Power and Light (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! http://www.manning.com/books/black