From: Tarek Other Date: 2008-11-13T06:43:59+09:00 Subject: Re: Issue with block and getting to local variables 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} > => # > > > 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? -- Posted via http://www.ruby-forum.com/.