From: "David A. Black" Date: 2004-10-05T03:31:14+09:00 Subject: Re: Kernel#eval taking a block 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)" > 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 > def initialize > @x = 1 > end > attr_reader :x > def get_binding > cool = "matz" > return binding() > 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 # > 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" :-) David -- David A. Black dblack@wobblini.net