cldwalker wrote:
> On Jul 23, 9:47 pm, Joel VanderWerf <vj... / path.berkeley.edu> wrote:
>> ghorner wrote:
>>>   begin puts "=> #{eval(input).inspect}"; rescue Exception; puts
>> Do you want
>>
>> eval(input, b)
>>
>> where b is a Binding that was constructed before the loop? Otherwise,
>> how will this support local vars?
> 
> Joel,
>   not sure I follow. In mini-irb this works:
> 
>   >> b = 2
>   => 2
>   >> 'b' * b
>   => "bb"
> 
> As does placing local variables before the loop being picked up by
> eval. Could you elaborate?
> Gabriel
> 


Here's a simplified version of your code:

$ cat mirb.rb
%w{readline rubygems}.each {|e| require e }
while (input = Readline.readline('>> ', true)) != 'exit'
   begin puts "=> #{eval(input).inspect}"; rescue Exception; puts
"Error: #{$!}" end
  end
$ ruby mirb.rb
 >> input
=> "input"


This is fixable using bindings:

$ cat mirb.rb
%w{readline rubygems}.each {|e| require e }
def get_binding; binding; end
b = get_binding
while (input = Readline.readline('>> ', true)) != 'exit'
   begin puts "=> #{eval(input, b).inspect}"; rescue Exception; puts
"Error: #{$!}" end
  end
$ ruby mirb.rb
 >> input

 >>

(Now, some might say that's still a bug, but at least it doesn't expose 
a local variable of mini-irb.)

-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407