Forum: Ruby closure & local_variables

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B97225f66bb5caac601b12735d430a0d?d=identicon&s=25 Marcin MielżyÅ?ski (Guest)
on 2006-03-03 22:49
(Received via mailing list)
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
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-03-03 23:07
(Received via mailing list)
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.
D111305c32e46f7dd2794a956208d347?d=identicon&s=25 E. Saynatkari (Guest)
on 2006-03-03 23:10
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
This topic is locked and can not be replied to.