[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Extract local variables from a block?

Josh French

7/4/2008 12:30:00 AM

Is it possible to extract local variables from within a block, while
standing outside said block? Here's an example which might illustrate
what I'm trying to do:

def local_vars_from(&block)
eval('local_variables', block).each do |var|
new_local_var = eval(var, block)
end
end

local_vars_from do
unknown_local_var = :blah
end

Of course, this example doesn't work at all. What I'm trying to
accomplish is a new variable in the current scope which mirrors the
variable inside the block. I'm pretty sure I'm misusing
local_variables; is there another approach to this?

Thanks,
j