From: ara.t.howard@... Date: 2006-07-10T22:16:46+09:00 Subject: Re: instance_exec On Mon, 10 Jul 2006 transfire@gmail.com wrote: > > Erik Veenstra wrote: >> Okay, criticizing somebody's work without providing a >> "solution", isn't nice at all... >> >> So, here's my version... >> >> gegroet, >> Erik V. - http://www.erikveen.dds.nl/ >> >> PS: I'm still curious about the reason for using a module. > > I think the idea was to save frm creting a singleton class, but at the > expense of a module I don't see why either. Anyway, here the version I > put in Facets. Please evaluate. > > module Kernel > > # Like instace_eval but allows parameters to be passed. > # > # The implementation is thread-safe thanks to the > # Thread.current.object_id trick, but it doesn't work with > # immediate values (Fixnums and friends), and most > # importantly it bombs when given a frozen object. > > def instance_exec(*args, &block) > mname = > "__instance_exec(#{Thread.current.object_id},#{caller.object_id})" > Object.class_eval{ define_method(mname, &block) } > begin > ret = send(mname, *args) > ensure > Object.class_eval{ undef_method(mname) } > end > ret > end > > end -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama