From: daniel Date: 2006-12-11T07:30:10+09:00 Subject: Re: Scope of block Gustav Paul schreef: > The following seems to work: > ######### > class BlockTest > def process(&block) > @block=block > end > > def myblock > instance_eval{@block}.call > end > end > > out_of_scope_var = "out of scope, me" > t = BlockTest.new > t.process {"var = #{out_of_scope_var}"} > > p t.myblock > #=> "var = out of scope, me" > ########### > Hope this helps, > Gustav Paul Hi paul, i know that's works, but i need it slightly differtent because you set out_of_scope_var before you create the block I want it to be accessible when you set it after you create the block With your method it is in the scope of the block I want the block to have access to the scope when you call it So this should work : class BlockTest def process(&block) @block=block end def myblock instance_eval{@block}.call end end t = BlockTest.new t.process {"var = #{out_of_scope_var}"} out_of_scope_var = "out of scope, me" p t.myblock But that gives : blocktest.rb:40: undefined local variable or method `out_of_scope_var' for main:Object (NameError) from blocktest.rb:34:in `myblock' from blocktest.rb:45 :( thanks anyway :)