From: transfire@... Date: 2006-07-08T03:22:54+09:00 Subject: Re: instance_exec Marcel Molina Jr. wrote: > On Sat, Jul 08, 2006 at 02:22:31AM +0900, ara.t.howard@noaa.gov wrote: > > > > i seems to recall someone came up with an impl of instance_exec > > (instance_eval > > that takes args) a while back - might have even been me! ;-) anyone > > remember? > > There is one in Rails' ActiveSupport: > > class Object > unless defined? instance_exec # 1.9 > def instance_exec(*arguments, &block) > block.bind(self)[*arguments] > end > end > end > > class Proc > def bind(object) > block, time = self, Time.now > (class << object; self end).class_eval do > method_name = "__bind_#{time.to_i}_#{time.usec}" > define_method(method_name, &block) > method = instance_method(method_name) > remove_method(method_name) > method > end.bind(object) > end > end Huh. That looks like the one I wrote a while back (minus the time stamp). Mauricio Fernandez's looks better though --think I'll have to rip it for Facets ;-) T.