Kernel.local_variables question

J

Jos Backus

Consider

def foo
a = "a"
b = 1
p Kernel.local_variables
end

Why doesn't this print anything? I would expect it to print

["a", "b"]

but instead it prints nothing.

--
Jos Backus _/ _/_/_/ Sunnyvale, CA
_/ _/ _/
_/ _/_/_/
_/ _/ _/ _/
jos at catnook.com _/_/ _/_/_/ require 'std/disclaimer'
 
S

Shashank Date

Jos said:
Consider

def foo
a = "a"
b = 1
p Kernel.local_variables
end

Why doesn't this print anything? I would expect it to print

["a", "b"]

but instead it prints nothing.

Which version of ruby and which platform?
It works for me:
------------------------------------------
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>irb -v
irb 0.9(02/07/03)

C:\>irb
irb(main):001:0> def foo; a = "a"; b = 1; p Kernel.local_variables; end
=> nil
irb(main):002:0> foo
["a", "b"]
=> nil
irb(main):003:0> exit

C:\>ruby -v
ruby 1.8.2 (2004-06-29) [i386-mswin32]

C:\>
 
J

Jos Backus

It works for me:
------------------------------------------
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>irb -v
irb 0.9(02/07/03)

C:\>irb
irb(main):001:0> def foo; a = "a"; b = 1; p Kernel.local_variables; end
=> nil
irb(main):002:0> foo
["a", "b"]
=> nil
irb(main):003:0> exit

C:\>ruby -v
ruby 1.8.2 (2004-06-29) [i386-mswin32]

C:\>

This is with the current ruby from the FreeBSD ports system:

ruby 1.8.2 (2004-07-29) [i386-freebsd6]

It doesn't work with today's HEAD either (just tried it), which is

ruby 1.9.0 (2004-12-16) [i386-freebsd6.0]

I figured with this working it would be possible to fake Python's `vars()',
useful for quick conversions of Python code.

--
Jos Backus _/ _/_/_/ Sunnyvale, CA
_/ _/ _/
_/ _/_/_/
_/ _/ _/ _/
jos at catnook.com _/_/ _/_/_/ require 'std/disclaimer'
 
N

nobu.nokada

Hi,

At Thu, 16 Dec 2004 13:43:15 +0900,
Jos Backus wrote in [ruby-talk:123764]:
This is with the current ruby from the FreeBSD ports system:

ruby 1.8.2 (2004-07-29) [i386-freebsd6]

It doesn't work with today's HEAD either (just tried it), which is

ruby 1.9.0 (2004-12-16) [i386-freebsd6.0]

It works for me.

$ ./ruby -v -e '
def foo
a = "a"
b = 1
p Kernel.local_variables
end
foo
'
ruby 1.9.0 (2004-12-16) [i686-linux]
["a", "b"]
 
J

Jos Backus

Nevermind, it would help if I called foo, which I wasn't. Duh.

My apologies, especially to Shashank and Nobu, for the noise. Been busy
porting a Python script to Ruby all day. Bad excuse, I know.

--
Jos Backus _/ _/_/_/ Sunnyvale, CA
_/ _/ _/
_/ _/_/_/
_/ _/ _/ _/
jos at catnook.com _/_/ _/_/_/ require 'std/disclaimer'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top