# Kernel#eval taking a block

**URL:** <https://rubytalk.org/t/kernel-eval-taking-a-block/13921>\
**Category:** ruby-talk\
**Created:** [3 October 2004 01:25 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921 "2004-10-03T01:25:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_Onoma](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@T\_Onoma](https://rubytalk.org/u/T_Onoma)\
**Post date:** [3 October 2004 01:25 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/1 "2004-10-03T01:25:37Z")

</div>

Is there a reason Kernel#eval won't take a block? I wrote this to overcome:

&nbsp;&nbsp;# Evaluate a Ruby source code string (or block) in the binding context  
&nbsp;&nbsp;def evalb( str=nil, binding=nil, &blk )  
&nbsp;&nbsp;&nbsp;&nbsp;if block\_given?  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Kernel.eval( "proc {|slf, blk| slf.instance\_eval(&blk)}",  
binding ).call( binding, blk )  
&nbsp;&nbsp;&nbsp;&nbsp;elsif str  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Kernel.eval( str, binding )  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

Although, I'm not sure it's exactly right --I put it together by a bit of  
trial and error.

T.

> **···**
>
> --  
> ( o \_ カラチ  
> // trans.  
> / \ [transami@runbox.com](mailto:transami@runbox.com)
> 
> I don't give a damn for a man that can only spell a word one way.  
> -Mark Twain

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [4 October 2004 00:20 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/2 "2004-10-04T00:20:03Z")

</div>

Hi,

At Sun, 3 Oct 2004 10:25:37 +0900,  
trans. (T. Onoma) wrote in [ruby-talk:114646]:

> Is there a reason Kernel#eval won't take a block? I wrote this to overcome:
> 
> &nbsp;&nbsp;# Evaluate a Ruby source code string (or block) in the binding context  
> &nbsp;&nbsp;def evalb( str=nil, binding=nil, &blk )  
> &nbsp;&nbsp;&nbsp;&nbsp;if block\_given?  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Kernel.eval( "proc {|slf, blk| slf.instance\_eval(&blk)}",  
> binding ).call( binding, blk )  
> &nbsp;&nbsp;&nbsp;&nbsp;elsif str  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Kernel.eval( str, binding )  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;end

It's evaluated in the Binding/Proc's context, but not in the  
context where it was created. I.E., it is equivalent to

&nbsp;&nbsp;binding.instance\_eval(&blk)

except that variables `slf' and `blk' will be altered if they  
exist in the context of `binding'.

Seems less meaningful.

> **···**
>
> --  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![T\_Onoma](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@T\_Onoma](https://rubytalk.org/u/T_Onoma)\
**Post date:** [4 October 2004 14:23 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/3 "2004-10-04T14:23:22Z")

</div>

Crud. I see. You are ( as always 😉 quite correct. Is there anyway to  
overcome? Back to the original question: why Kernel#eval can't take a block?

Thanks,  
T.

> **···**
>
> On Sunday 03 October 2004 08:20 pm, nobu.nokada@softhome.net wrote:
> 
> > Hi,
> > 
> > At Sun, 3 Oct 2004 10:25:37 +0900,
> > 
> > trans. (T. Onoma) wrote in [ruby-talk:114646]:  
> > \> Is there a reason Kernel#eval won't take a block? I wrote this to  
> > \> overcome:  
> > \>  
> > \> # Evaluate a Ruby source code string (or block) in the binding context  
> > \> def evalb( str=nil, binding=nil, &blk )  
> > \> if block\_given?  
> > \> Kernel.eval( "proc {|slf, blk| slf.instance\_eval(&blk)}",  
> > \> binding ).call( binding, blk )  
> > \> elsif str  
> > \> Kernel.eval( str, binding )  
> > \> end  
> > \> end
> > 
> > It's evaluated in the Binding/Proc's context, but not in the  
> > context where it was created. I.E., it is equivalent to
> > 
> > &nbsp;&nbsp;binding.instance\_eval(&blk)
> > 
> > except that variables `slf' and `blk' will be altered if they  
> > exist in the context of `binding'.
> > 
> > Seems less meaningful.

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [4 October 2004 15:11 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/4 "2004-10-04T15:11:24Z")

</div>

Hi,

> **···**
>
> In message "Re: Kernel#eval taking a block" on Mon, 4 Oct 2004 23:23:22 +0900, "trans. (T. Onoma)" \<transami@runbox.com\> writes:
> 
> > Back to the original question: why Kernel#eval can't take a block?
> 
> Because it's useless, for my eyes at least. What do you want to  
> accomplish by eval with a block?
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matz.

---

<div class="post-metadata">

**Author:** ![T\_Onoma](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@T\_Onoma](https://rubytalk.org/u/T_Onoma)\
**Post date:** [4 October 2004 18:00 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/5 "2004-10-04T18:00:29Z")

</div>

How to get locals into evaluation?

class T  
&nbsp;&nbsp;&nbsp;&nbsp;def initialize  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@x = 1  
&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;attr\_reader :x  
&nbsp;&nbsp;&nbsp;def get\_binding  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cool = "matz"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return binding()  
&nbsp;&nbsp;&nbsp;end  
end  
t = T.new  
tb = t.get\_binding  
eval "cool", tb #=\> "matz"  
a = proc {|c| c.upcase}  
eval "cool = a.call(cool)", tb

NameError: undefined local variable or method `a' for #\<T:0x4032f038 @x=1\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):15:in `get\_binding'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):15:in `get\_binding'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):19

t.

> **···**
>
> On Monday 04 October 2004 11:11 am, Yukihiro Matsumoto wrote:
> 
> > Hi,
> > 
> > In message "Re: Kernel#eval taking a block" \> \> on Mon, 4 Oct 2004 23:23:22 +0900, "trans. (T. Onoma)" \<transami@runbox.com\> writes:  
> > \>Back to the original question: why Kernel#eval can't take a block?
> > 
> > Because it's useless, for my eyes at least. What do you want to  
> > accomplish by eval with a block?

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [4 October 2004 18:31 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/6 "2004-10-04T18:31:14Z")

</div>

Hi --

> **···**
>
> On Tue, 5 Oct 2004, trans. (T. Onoma) wrote:
> 
> > On Monday 04 October 2004 11:11 am, Yukihiro Matsumoto wrote:  
> > \> Hi,  
> > \>  
> > \> In message "Re: Kernel#eval taking a block" \> \> \> \> on Mon, 4 Oct 2004 23:23:22 +0900, "trans. (T. Onoma)" \> \<transami@runbox.com\> writes:  
> > \> \>Back to the original question: why Kernel#eval can't take a block?  
> > \>  
> > \> Because it's useless, for my eyes at least. What do you want to  
> > \> accomplish by eval with a block?
> > 
> > How to get locals into evaluation?
> > 
> > class T  
> > &nbsp;&nbsp;&nbsp;&nbsp;def initialize  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@x = 1  
> > &nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;&nbsp;attr\_reader :x  
> > &nbsp;&nbsp;&nbsp;def get\_binding  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cool = "matz"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return binding()  
> > &nbsp;&nbsp;&nbsp;end  
> > end  
> > t = T.new  
> > tb = t.get\_binding  
> > eval "cool", tb #=\> "matz"  
> > a = proc {|c| c.upcase}  
> > eval "cool = a.call(cool)", tb
> > 
> > NameError: undefined local variable or method `a' for #\<T:0x4032f038 @x=1\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):15:in `get\_binding'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):15:in `get\_binding'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):19
> 
> But if you're eval'ing in another binding, 'a' won't mean anything in  
> a string or a block, will it? In other words: you're trying to mix  
> locals from two bindings in one expression, which somewhat defeats the  
> purpose of having "locals" 🙂
> 
> David
> 
> --  
> David A. Black  
> dblack@wobblini.net

---

<div class="post-metadata">

**Author:** ![T\_Onoma](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@T\_Onoma](https://rubytalk.org/u/T_Onoma)\
**Post date:** [4 October 2004 18:51 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/7 "2004-10-04T18:51:20Z")

</div>

I see. So this kind of thing just can't happen I take it. (Hmm... I think we  
discussed this kind of thing on core once.) It would be nice if we could pass  
in locals to the binding:

&nbsp;&nbsp;eval(tb, a) { |a| cool = a.call(cool) }

It might also be nice if this could be done without "stepping on toes" (i.e.  
overwriting binding's locals).

T.

> **···**
>
> On Monday 04 October 2004 02:31 pm, David A. Black wrote:
> 
> > \> eval "cool = a.call(cool)", tb  
> > \>  
> > \> NameError: undefined local variable or method `a' for #\<T:0x4032f038  
> > \> @x=1\> from (irb):15:in `get\_binding'  
> > \> from (irb):15:in `get\_binding'  
> > \> from (irb):19
> > 
> > But if you're eval'ing in another binding, 'a' won't mean anything in  
> > a string or a block, will it? In other words: you're trying to mix  
> > locals from two bindings in one expression, which somewhat defeats the  
> > purpose of having "locals" 🙂

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [4 October 2004 19:49 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/8 "2004-10-04T19:49:52Z")

</div>

trans. (T. Onoma) wrote:

> I see. So this kind of thing just can't happen I take it. (Hmm... I think we discussed this kind of thing on core once.) It would be nice if we could pass in locals to the binding:
> 
> &nbsp;&nbsp;eval(tb, a) { |a| cool = a.call(cool) }
> 
> It might also be nice if this could be done without "stepping on toes" (i.e. overwriting binding's locals).

You can use this workaround:

eval("cool = yield.call(cool)", tb) { a }

And in this case also:

eval("cool = yield(cool)", tb, &a)

Regards,  
Florian Gross

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [8 October 2004 05:49 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/9 "2004-10-08T05:49:46Z")

</div>

Hi,

At Tue, 5 Oct 2004 03:51:20 +0900,  
trans. (T. Onoma) wrote in [ruby-talk:114847]:

> I see. So this kind of thing just can't happen I take it. (Hmm... I think we  
> discussed this kind of thing on core once.) It would be nice if we could pass  
> in locals to the binding:
> 
> &nbsp;&nbsp;eval(tb, a) { |a| cool = a.call(cool) }
> 
> It might also be nice if this could be done without "stepping on toes" (i.e.  
> overwriting binding's locals).

eval("proc{|cool|}", tb).call(a.call(eval("cool", tb)))

> **···**
>
> --  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![T\_Onoma](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@T\_Onoma](https://rubytalk.org/u/T_Onoma)\
**Post date:** [4 October 2004 20:30 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/10 "2004-10-04T20:30:56Z")

</div>

Oh reeeaaaalllly...... darn it!

LocalJumpError: no block given  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):5:in `get\_binding'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):5:in `get\_binding'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):9

Is this a 1.9 thing?

T.

> **···**
>
> On Monday 04 October 2004 03:49 pm, Florian Gross wrote:
> 
> > trans. (T. Onoma) wrote:  
> > \> I see. So this kind of thing just can't happen I take it. (Hmm... I think  
> > \> we discussed this kind of thing on core once.) It would be nice if we  
> > \> could pass in locals to the binding:  
> > \>  
> > \> eval(tb, a) { |a| cool = a.call(cool) }  
> > \>  
> > \> It might also be nice if this could be done without "stepping on toes"  
> > \> (i.e. overwriting binding's locals).
> > 
> > You can use this workaround:
> > 
> > eval("cool = yield.call(cool)", tb) { a }
> > 
> > And in this case also:
> > 
> > eval("cool = yield(cool)", tb, &a)

---

<div class="post-metadata">

**Author:** ![T\_Onoma](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@T\_Onoma](https://rubytalk.org/u/T_Onoma)\
**Post date:** [8 October 2004 10:51 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/11 "2004-10-08T10:51:21Z")

</div>

What are you?

(Note: if this statement doesn't cross the language barrier well, just know  
that it is a big compliment!)

T.

> **···**
>
> On Friday 08 October 2004 01:49 am, nobu.nokada@softhome.net wrote:
> 
> > Hi,
> > 
> > At Tue, 5 Oct 2004 03:51:20 +0900,
> > 
> > trans. (T. Onoma) wrote in [ruby-talk:114847]:  
> > \> I see. So this kind of thing just can't happen I take it. (Hmm... I think  
> > \> we discussed this kind of thing on core once.) It would be nice if we  
> > \> could pass in locals to the binding:  
> > \>  
> > \> eval(tb, a) { |a| cool = a.call(cool) }  
> > \>  
> > \> It might also be nice if this could be done without "stepping on toes"  
> > \> (i.e. overwriting binding's locals).
> > 
> > eval("proc{|cool|}", tb).call(a.call(eval("cool", tb)))

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [4 October 2004 21:10 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/12 "2004-10-04T21:10:05Z")

</div>

trans. (T. Onoma) wrote:

> > > eval(tb, a) { |a| cool = a.call(cool) }
> > > 
> > > It might also be nice if this could be done without "stepping on toes"  
> > > (i.e. overwriting binding's locals).
> > 
> > You can use this workaround:
> > 
> > eval("cool = yield.call(cool)", tb) { a }
> 
> LocalJumpError: no block given  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):5:in `get\_binding'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):9
> 
> Is this a 1.9 thing?

Yikes, sorry. It only works when no explicit binding is given. ☹

So the only way seems using Object.\_id2ref and interpolation for now.

Regards,  
Florian Gross

---

<div class="post-metadata">

**Author:** ![Markus](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Markus](https://rubytalk.org/u/Markus)\
**Post date:** [8 October 2004 15:18 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/13 "2004-10-08T15:18:15Z")

</div>

> \> Hi,  
> \>  
> \> At Tue, 5 Oct 2004 03:51:20 +0900,  
> \>  
> \> trans. (T. Onoma) wrote in [ruby-talk:114847]:  
> \> \> I see. So this kind of thing just can't happen I take it. (Hmm... I think  
> \> \> we discussed this kind of thing on core once.) It would be nice if we  
> \> \> could pass in locals to the binding:  
> \> \>  
> \> \> eval(tb, a) { |a| cool = a.call(cool) }  
> \> \>  
> \> \> It might also be nice if this could be done without "stepping on toes"  
> \> \> (i.e. overwriting binding's locals).  
> \>  
> \> eval("proc{|cool|}", tb).call(a.call(eval("cool", tb)))
> 
> What are you?
> 
> (Note: if this statement doesn't cross the language barrier well, just know  
> that it is a big compliment!)

I agree. That's a very clever hack.

> class T  
> &nbsp;&nbsp;&nbsp;&nbsp;def initialize  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@x = 1  
> &nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;attr\_reader :x  
> &nbsp;&nbsp;&nbsp;def get\_binding  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cool = "matz"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return binding()  
> &nbsp;&nbsp;&nbsp;end  
> end

=\> nil

> t = T.new

=\> #\<T:0x400bee3c @x=1\>

> tb = t.get\_binding

=\> #\<Binding:0x400b85a0\>

> eval "cool",tb

=\> "matz"

> a = proc { |s| s.upcase }

=\> #\<Proc:0x400b0abc@(irb):33\>

> eval("proc{|cool|}", tb).call(a.call(eval("cool", tb)))

=\> nil

> eval "cool",tb

=\> "MATZ"

So basically, what you have is a getter:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vvvvvvvvvvvvvvv  
eval("proc{|cool|}", tb).call(a.call(eval("cool", tb)))  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

and a setter. We could even abstract them (baby steps here; I realize  
this opens up all sorts of possibilities):

def tb.(v)  
&nbsp;&nbsp;&nbsp;&nbsp;eval(v.to\_s,self)  
&nbsp;&nbsp;&nbsp;&nbsp;end

def tb.=(v,x)  
&nbsp;&nbsp;&nbsp;&nbsp;eval("proc{|#{v}|}",self).call(x)  
&nbsp;&nbsp;&nbsp;&nbsp;end

(Using = also gives us the assignment chaining semantics).

Very nifty!

-- Markus

> **···**
>
> On Fri, 2004-10-08 at 03:51, trans. (T. Onoma) wrote:
> 
> > On Friday 08 October 2004 01:49 am, nobu.nokada@softhome.net wrote:

---

<div class="post-metadata">

**Author:** ![Markus](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Markus](https://rubytalk.org/u/Markus)\
**Post date:** [5 October 2004 04:41 UTC](https://rubytalk.org/t/kernel-eval-taking-a-block/13921/14 "2004-10-05T04:41:47Z")

</div>

What about:

class T  
&nbsp;&nbsp;&nbsp;&nbsp;def initialize  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@x = 1  
&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;attr\_reader :x  
&nbsp;&nbsp;&nbsp;def get\_binding  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cool = "matz"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return binding()  
&nbsp;&nbsp;&nbsp;end  
end  
t = T.new  
tb = t.get\_binding  
eval "cool", tb #=\> "matz"

# Does not work:  
# a = proc {|c| c.upcase}  
# so instead:  
class \<\<t; def a(c); c.upcase; end; end

eval "cool = a.call(cool)", tb #"MATZ"

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I realize it isn't an exact parallel to what you seemed to be  
wanting (but then again, it's hard to guess the "proper" semantics of  
hypothetical language extensions). Would it work for what you are  
trying to accomplish? If not, why not? I'll admit I don't quite see  
the goal, nor understand what overlaying two "local" scopes would mean.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If the above isn't what you want, would something like:

tb[:a] = proc {|c| c.upcase}

(which doesn't work, but at least seems to me to be easier to interpret  
the intension of) be a good way of describing what you are trying to do?

-- Markus

> **···**
>
> On Mon, 2004-10-04 at 14:10, Florian Gross wrote:
> 
> > trans. (T. Onoma) wrote:
> > 
> > \>\>\> eval(tb, a) { |a| cool = a.call(cool) }  
> > \>\>\>  
> > \>\>\>It might also be nice if this could be done without "stepping on toes"  
> > \>\>\>(i.e. overwriting binding's locals).  
> > \>\>  
> > \>\>You can use this workaround:  
> > \>\>  
> > \>\>eval("cool = yield.call(cool)", tb) { a }  
> > \> LocalJumpError: no block given  
> > \> from (irb):5:in `get\_binding'  
> > \> from (irb):5:in `get\_binding'  
> > \> from (irb):9  
> > \>  
> > \> Is this a 1.9 thing?
> > 
> > Yikes, sorry. It only works when no explicit binding is given. ☹
> > 
> > So the only way seems using Object.\_id2ref and interpolation for now.
