From: Markus Date: 2004-10-05T13:41:47+09:00 Subject: Re: Kernel#eval taking a block 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. What about: 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" # Does not work: # a = proc {|c| c.upcase} # so instead: class <