# Eval / current binding

**URL:** <https://www.ruby-forum.com/t/eval-current-binding/121794>\
**Category:** Ruby\
**Created:** [November 30, 2007, 10:43pm UTC](https://www.ruby-forum.com/t/eval-current-binding/121794 "2007-11-30T22:43:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![redroofgreentree](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@redroofgreentree](https://www.ruby-forum.com/u/redroofgreentree)\
**Post date:** [November 30, 2007, 10:43pm UTC](https://www.ruby-forum.com/t/eval-current-binding/121794/1 "2007-11-30T22:43:46Z")

</div>

Hey,

So I’ve looked at module\_eval, class\_eval, and Kernel#eval

and I’m pretty sure that what I want to do is to do Kernel#eval(“blah  
…  
some code”, global\_environment)

where by global\_environment I mean the global\_context or the  
global\_binding

The problem now … is that I don’t know how to access this global  
environment / global context / global binding … is there a function  
that I  
can call that will

(1) get me the global binding / global env / global context or  
(2) a function that I can call that will get me the current binding /  
env  
/ context

Thanks,  
(when replying please cc the list and me)

---

<div class="post-metadata">

**Author:** ![redroofgreentree](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@redroofgreentree](https://www.ruby-forum.com/u/redroofgreentree)\
**Post date:** [December 1, 2007, 6:40am UTC](https://www.ruby-forum.com/t/eval-current-binding/121794/2 "2007-12-01T06:40:59Z")

</div>

On Nov 30, 3:42 pm, redroofgreentree [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> global\_binding  
> (when replying please cc the list and me)  
> The TOPLEVEL\_BINDING constant…but the standard disclaimer is don’t  
> use eval (depends on what you’re doing though). It is generally not  
> safe unless you have 100% control over the input, because it can do  
> everything ruby can (i.e., eval doesn’t run in any kind of sandbox),  
> so in an untrusted context, it’s dangerous.

Regards,  
Jordan
