On Wed, 28 Sep 2005, Eric Mahurin wrote:

> --- "Kroeger Simon (ext)" <simon.kroeger.ext / siemens.com>
> wrote:
>>> -----Original Message-----
>>> From: Michael Roth [mailto:mroth / nessie.de]
>>> Sent: Wednesday, September 28, 2005 3:12 PM
>>> To: ruby-talk ML
>>> Subject: Re: creating independent lambdas in loops
>>>
>>> Michael Roth wrote:
>>>
>>>> Already tried. Doesn't work... :-\
>>>
>>> Argh, stop. Looks like it works. But only if 'multi'
>> doesn't appears
>>> somewhere before the each-loop.
>>
>> Completely true. If a variable of that name is already
>> defined it is
>> used (and no local variables are created).
>
> Does anyone else find this "feature" useful?
>
> Is there any way to create a local variable to a block where
> that variable name is already used?  Most other languages have
> this ability but it looks like ruby doesn't.

it's everywhere in ruby - it's called the 'block' ;-)

   harp:~ > cat a.rb
   def scope *vars; yield *vars; end

   x, y = 0b101010, 0b0

   p y

   scope(x){|y| p y}


   harp:~ > ruby a.rb
   0
   42


cheers.

-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze.  --Nagarjuna
===============================================================================