From: Gavin Sinclair Date: 2003-09-11T12:56:45+09:00 Subject: Re: What *are* variables? Which are nil now? > [Hugh:] > >> Variables are not objects; it's as simple as that. They are sticky >> notes. You can get a list of local variables in any scope with >> Kernel::local_variables. Then you can eval them to find out what they > > thanks, I missed that one. > >> are. >> >> You can get a list of variables in other scopes as well. I have a >> marvellous proof for this, which this margin is too small to contain. > > I seem to be needing large margins for my errors, I'll send you one! :-) > I'd like to know how to extract this info from Ruby. It might not have > helped in my case though, but would be generally good to > have. > Heh, all I had in mind was this: if you can get a Binding to another scope, then you can execute "local_variables" in that binding. To wit: def foo a = 1 b = 2 c = 3 return binding end b = foo # local_variables # ["_", "b"] eval "local_variables", b # ["a", "b", "c"] eval "a", b # 1 eval "b", b # 2 eval "b" # I don't know if/how you can get a binding to another scope without explicitly arranging it. Not through Kernel::caller, for better or worse. Gavin # Now, who can tell me what that "_" local variable is? Extra points for # telling me why I should have known all along.