From: NoonKnight Date: 2006-12-11T22:40:08+09:00 Subject: Re: Scope of block you could add an eval() into your example code, so that: t = BlockTest.new t.process { "var = #{out_of_scope_var}" } out_of_scope_var = "daniel" p t.myblock.call would become: t = BlockTest.new t.process { "var = #{eval('out_of_scope_var'}" } out_of_scope_var = "daniel" p t.myblock.call hope that helps. --noon daniel wrote: > Hello i have a question about scopes of block > I want to define a block at one time. > But when it get's called it should have the scope (vars ed ) > of the calling environement > > Example : > ------------------------------ > > class BlockTest > > attr_accessor :myblock > > def process(&block) > self.myblock = block > end > end > > > t = BlockTest.new > t.process { > > "var = #{out_of_scope_var}" > } > > out_of_scope_var = "daniel" > p t.myblock.call > > Results in : > > blocktest.rb:15: undefined local variable or method `out_of_scope_var' > for main:Object (NameError) from blocktest.rb:19 > > How can i call the proc so that the out_of_scope_var is known : > > result would be : > > so i would get : > > daniel-wijnands-powerbook58-2:~/jim/vendor/plugins/widget_grid/lib > danielwijnands$ ruby blocktest.rb > "var = daniel"