On Wed, Nov 12, 2008 at 3:43 PM, Tarek Other <cashew250 / yahoo.com> wrote:
> Robert Klemme wrote:
>> On 12.11.2008 21:31, Tarek Other wrote:
>>> Also I'd like that
>>> block of code to be attached to a variable so I can call it were and
>>> when ever.
>>
>> irb(main):001:0> bl = lambda {|a,b| puts a, b}
>> => #<Proc:0x7ff98cf4@(irb):1>
>>
>>  > Ok I'm new to ruby and want to do the following, I want to define a
>>  > function that is a ble to call a block and I want that block to have
>>  > access to the calling function's local variables.
>>
>> irb(main):002:0> def fun
>> irb(main):003:1> x = 1
>> irb(main):004:1> y = 2
>> irb(main):005:1> yield x,y
>> irb(main):006:1> end
>> => nil
>> irb(main):007:0> fun &bl
>> 1
>> 2
>> => nil
>> irb(main):008:0>
>>
>> Kind regards
>>
>>   robert
>
> Thank you Robert but the problem with that approach is the need to pass
> the variables into the block (in this case x,y has to be passed in). I
> wanted to avoid that because I would have ton of local variables that I
> would have to pass in. Is there any way to do what I want?

x, y (and a, b) are objects.  They don't have to be integers.  They
could be arrays, hashes, etc.

Todd