[MacRuby-devel] eval() Behavior Difference Between Ruby and MacRuby

Braxton Sherouse sherouse at email.virginia.edu
Thu Mar 8 11:14:13 PST 2012


Hello, all. I'm new to the list (and to MacRuby!), so I give my
apologies in advance for any newbie indiscretions.

I was working today with MacRuby as a scripting language within a
Cocoa app, and found a difference between how Ruby and MacRuby's eval
functions relate to their calling context.

Here's a reduction:

% irb --version
irb 0.9.5(05/04/13)

% irb
>> eval("f = 12")
=> 12
>> f
=> 12

% macirb --version
DietRB (0.6.1)

% macirb
irb(main):001:0> eval("f = 12")
=> 12
irb(main):002:0> f
NameError: undefined local variable or method `f' for main:TopLevel
	

I'm sure I'm missing something super basic. I followed a number of
false leads in trying to figure this out before emailing the list,
including checking out the $SAFE global (0 in both cases), and
constructing Bindings to the calling context (same result).

Thanks in advance for your patience and your help!

Best,
Braxton Sherouse


More information about the MacRuby-devel mailing list