# Clearing TOPLEVEL\_BINDING for reuse

**URL:** <https://www.ruby-forum.com/t/clearing-toplevel-binding-for-reuse/189707>\
**Category:** Ruby\
**Created:** [June 5, 2010, 8:41pm UTC](https://www.ruby-forum.com/t/clearing-toplevel-binding-for-reuse/189707 "2010-06-05T20:41:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 5, 2010, 8:41pm UTC](https://www.ruby-forum.com/t/clearing-toplevel-binding-for-reuse/189707/1 "2010-06-05T20:41:13Z")

</div>

Is there anyway to delete all the local and instance variables in a  
Binding?

I’ve been working on a test framework and ideally I’d like the tests  
to run at the toplevel rather than within the scope of some class. But  
to do this I need to clear out the variables between each test script.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 5, 2010, 9:05pm UTC](https://www.ruby-forum.com/t/clearing-toplevel-binding-for-reuse/189707/2 "2010-06-05T21:05:48Z")

</div>

On 2010-06-05 11:40:25 -0700, Intransition said:

> Is there anyway to delete all the local and instance variables in a  
> Binding?
> 
> I’ve been working on a test framework and ideally I’d like the tests  
> to run at the toplevel rather than within the scope of some class. But  
> to do this I need to clear out the variables between each test script.

Binding objects are not mutable, nor would I suggest this as an  
implementation strategy.

Rein H.

> **[Puppet Infrastructure & IT Automation at Scale | Puppet by Perforce](https://www.puppet.com/)**
>
> Puppet is the industry-leading automation solution for configuration management, compliance, CI/CD, patch management, IT automation, and more.

[http://reinh.com](http://reinh.com)

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 6, 2010, 2:09am UTC](https://www.ruby-forum.com/t/clearing-toplevel-binding-for-reuse/189707/3 "2010-06-06T02:09:37Z")

</div>

On Jun 5, 3:05 pm, Rein H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> implementation strategy.  
> Any suggestions?

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 6, 2010, 2:20am UTC](https://www.ruby-forum.com/t/clearing-toplevel-binding-for-reuse/189707/4 "2010-06-06T02:20:45Z")

</div>

On 2010-06-05 17:09:06 -0700, Intransition said:

> > Binding objects are not mutable, nor would I suggest this as an  
> > implementation strategy.
> 
> Any suggestions?

There are at least 8 Ruby testing frameworks (that I’m aware of). I  
would recommend examining existing implementations. Nothing I could  
suggest in this space would be as comprehensive or accurate as the open  
source prior art available to you.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 6, 2010, 6:35am UTC](https://www.ruby-forum.com/t/clearing-toplevel-binding-for-reuse/189707/5 "2010-06-06T06:35:19Z")

</div>

On 2010-06-05 20:52:01 -0700, Intransition said:

> After all, what is TOPLEVEL anyway?
> 
> Funny how things can seem so complicated, but turn out the be so  
> incredibly simple.
> 
> Thanks for the help.

Or that.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 6, 2010, 5:52am UTC](https://www.ruby-forum.com/t/clearing-toplevel-binding-for-reuse/189707/6 "2010-06-06T05:52:34Z")

</div>

On Jun 5, 8:20 pm, Rein H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> There are at least 8 Ruby testing frameworks (that I’m aware of). I  
> would recommend examining existing implementations. Nothing I could  
> suggest in this space would be as comprehensive or accurate as the open  
> source prior art available to you.

Actually it turned out to be quite simple:

Object.new

After all, what is TOPLEVEL anyway?

Funny how things can seem so complicated, but turn out the be so  
incredibly simple.

Thanks for the help.
