From: "Ara.T.Howard" Date: 2005-09-20T01:21:37+09:00 Subject: Re: help with tricky proc/binding issue On Tue, 20 Sep 2005, Robert Klemme wrote: > Hacky but nice! For thread safety how about: what i think to be the final version: class Object def evaluate(*a, &b) ret, sent = nil loop do m = "____evaluate____#{ Thread::current.object_id }____#{ rand 666 }____#{ rand 42 }____" klass = Class === self ? self : self::class begin klass.module_eval{ define_method m, &b } ret = send(sent = m, *a) ensure begin klass.module_eval{ remove_method m } ensure break if sent end end end ret end end class C def y 42 end end b = lambda{|x| p [x, y, self]} c = C::new x = 42 c.evaluate(x, &b) #=> [42, 42, #] -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================