# Closure & local\_variables

**URL:** <https://www.ruby-forum.com/t/closure-local-variables/54409>\
**Category:** Ruby\
**Created:** [March 3, 2006, 10:49pm UTC](https://www.ruby-forum.com/t/closure-local-variables/54409 "2006-03-03T22:49:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin\_MielSSS\_ySSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@Marcin\_MielSSS\_ySSS](https://www.ruby-forum.com/u/Marcin_MielSSS_ySSS)\
**Post date:** [March 3, 2006, 10:49pm UTC](https://www.ruby-forum.com/t/closure-local-variables/54409/1 "2006-03-03T22:49:07Z")

</div>

Hello,

given:

l=lambda{p local\_variables;p a}  
a=:whatever  
l[]

I know that ‘a’ variable shoud not be visible for closure, but why  
local\_variables reports that it exists ? Is this behaviour intended ?

lopex

---

<div class="post-metadata">

**Author:** ![Marcin\_MielSSS\_ySSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@Marcin\_MielSSS\_ySSS](https://www.ruby-forum.com/u/Marcin_MielSSS_ySSS)\
**Post date:** [March 3, 2006, 11:07pm UTC](https://www.ruby-forum.com/t/closure-local-variables/54409/2 "2006-03-03T23:07:24Z")

</div>

On Mar 3, 2006, at 4:48 PM, Marcin MielÅ¼yÅ?ski wrote:

> lopex

l is closing over main, main has a local\_variables method, that is  
what is being called not the proc’s local\_variables.

---

<div class="post-metadata">

**Author:** ![Marcin\_MielSSS\_ySSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@Marcin\_MielSSS\_ySSS](https://www.ruby-forum.com/u/Marcin_MielSSS_ySSS)\
**Post date:** [March 3, 2006, 11:10pm UTC](https://www.ruby-forum.com/t/closure-local-variables/54409/3 "2006-03-03T23:10:13Z")

</div>

Marcin MielÅ¼yÅ?ski wrote:

> Hello,
> 
> given:
> 
> l=lambda{p local\_variables;p a}  
> a=:whatever  
> l[]
> 
> I know that ‘a’ variable shoud not be visible for closure, but why  
> local\_variables reports that it exists ? Is this behaviour intended ?

Well, #local\_variables is a method call so it resolves  
at call time (at which point a is included). You could  
also #eval ‘a’ at that point 🙂

> lopex

E
