On Fri, Nov 10, 2006, Phil Tomson wrote:
> Given that binding_of_caller seems to be broke in 1.8.5, would
> something like this work for you?:
> 
> class IRB_Evaler
>    def initialize scope
>      @scope = scope
>    end
>     def irb_eval(lines)
>       eval(lines.join("\n"),@scope)
>     end
>  end
>  evaler = IRB_Evaler.new binding
>  evaler.irb_eval( ['a = :foo', 'b = :bar'] )
>  puts a  #=> foo

It might work, but it brings up another problem, namely that I'm trying
to keep the interface clean for the caller.

Here's a more complete explanation of the problem, to hopefully give a
little context:

- There are a bunch of lines in the readline history
- a caller in irb can request to re-run a number of those (with the h!
  method)
- The h! method calls irb_eval, a private method, which in turn fetches
  the lines from the history and evals them

So I want to retain the "h! <number>" semantics, but somewhere I need to
get the binding where h! is called.  That precludes the previously
mentioned solution of just tacking a block on to the call to get the
block's binding.

What might work, but I haven't tried yet, is essentially doing what you
suggest in the .irbrc's top-level scope and hoping that it is the same
as the irb prompt's scope.

I'll write again once I've got a chance to try that.

Ben