Hi --

On Fri, 10 Nov 2006, Ben Bleything wrote:

> Hi all,
>
> As part of my IRB shell history hack (shameless plug[1]), I need to be
> able to access the caller's binding.  Essentially, I need to be able to
> do this:
>
>    def irb_eval( lines, scope )
>      eval(lines.join("\n"), scope)
>    end
>
>    irb_eval( ['a = :foo', 'b = :bar'], binding )
>
> ... but without explicitly passing the binding.  The goal is this:
>
>    irb_eval( ['a = :foo', 'b = :bar'] )
>
>    puts a
>    => :foo
>
>    puts b
>    => :bar
>
> Is this even possible?  As it is, the eval happens inside of irb_eval's
> scope (I'm assuming... wherever it happens, I can't see the results when
> it's done) which puts a cramp in my plans for world domination via cute
> IRB hacks.
>
> Help?

Do you know about Binding.of_caller by Florian Gross?  I'm not sure
where it's distributed from but you'll find it via Google.


David

-- 
                   David A. Black | dblack / rubypal.com
Author of "Ruby for Rails"   [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog)        [2] | Co-director, Ruby Central, Inc.   [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com    | [4] http://www.rubycentral.org