# What's the purpose of IRB.confand/or TOPLEVEL\_BINDING?

**URL:** <https://www.ruby-forum.com/t/whats-the-purpose-of-irb-confand-or-toplevel-binding/168542>\
**Category:** Ruby\
**Created:** [May 22, 2009, 6:28am UTC](https://www.ruby-forum.com/t/whats-the-purpose-of-irb-confand-or-toplevel-binding/168542 "2009-05-22T06:28:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghorner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a183cd/32.png) [@ghorner](https://www.ruby-forum.com/u/ghorner)\
**Post date:** [May 22, 2009, 6:28am UTC](https://www.ruby-forum.com/t/whats-the-purpose-of-irb-confand-or-toplevel-binding/168542/1 "2009-05-22T06:28:47Z")

</div>

Hi all,  
I’m peering into irb’s internals and am wondering what’s the purpose  
of IRB.conf[:CONTEXT\_MODE]? I understand most of the ruby code but all  
my googling has yet to bring up _anyone_ who uses this. Here is a link  
to the beginning of it’s implementation in irb:  
[http://github.com/akitaonrails/ruby191-stable-mirror/blob/c1a8d6cd2bd595ae3985edd2314f48d3d1a92188/lib/irb/workspace.rb#L21](http://github.com/akitaonrails/ruby191-stable-mirror/blob/c1a8d6cd2bd595ae3985edd2314f48d3d1a92188/lib/irb/workspace.rb#L21)

To summarize the implementation, IRB.conf[:CONTEXT\_MODE] can be set to  
one of 4 values: 0,1,2,3 (default is 3). Depending on the value, a  
binding is created for use when evaluating a line in irb:

0: eval(“proc{binding}.call”, TOPLEVEL\_BINDING …)  
1: creates a binding to a temporary file  
2: thread friendly binding from an irb file  
3: eval(“def irb\_binding; binding; end; irb\_binding”,  
TOPLEVEL\_BINDING …)

Right off the bat, I don’t know the use cases for cases 1 and 2. Is a  
binding in a temporary file perhaps more secure? As for cases 0 and 3  
rue on irc helped me understand the difference between them: case 0  
the binding has access to local variables of TOPLEVEL\_BINDING while  
case 3 doesn’t. But when I grep in ruby’s source, the only mention of  
TOPLEVEL\_BINDING is in irb libs and erb.rb. So of what use is case 0  
when almost no libraries use TOPLEVEL\_BINDING and when the binding  
could just very well be TOPLEVEL\_BINDING itself?

Thoughts, insights?  
Thanks,  
Gabriel

---

<div class="post-metadata">

**Author:** ![ghorner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a183cd/32.png) [@ghorner](https://www.ruby-forum.com/u/ghorner)\
**Post date:** [May 22, 2009, 8:21pm UTC](https://www.ruby-forum.com/t/whats-the-purpose-of-irb-confand-or-toplevel-binding/168542/2 "2009-05-22T20:21:13Z")

</div>

On May 21, 2:43 am, ghorner [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 0: eval(“proc{binding}.call”, TOPLEVEL\_BINDING …)  
> TOPLEVEL\_BINDING is in irb libs and erb.rb. So of what use is case 0  
> when almost no libraries use TOPLEVEL\_BINDING and when the binding  
> could just very well be TOPLEVEL\_BINDING itself?
> 
> Thoughts, insights?  
> Thanks,  
> Gabriel

I know some of irb’s confusing, but is this really that confusing? Any  
takers?  
Gabriel
