# Extract local variables from a block?

**URL:** <https://www.ruby-forum.com/t/extract-local-variables-from-a-block/142169>\
**Category:** Ruby\
**Created:** [July 4, 2008, 2:35am UTC](https://www.ruby-forum.com/t/extract-local-variables-from-a-block/142169 "2008-07-04T02:35:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfrench](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c77e96/32.png) [@jfrench](https://www.ruby-forum.com/u/jfrench)\
**Post date:** [July 4, 2008, 2:35am UTC](https://www.ruby-forum.com/t/extract-local-variables-from-a-block/142169/1 "2008-07-04T02:35:50Z")

</div>

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
