From: Ryan Leavengood Date: 2005-12-06T03:04:45+09:00 Subject: Re: limiting how long a method is permiited to run On 12/5/05, Brian Buckley wrote: > > Is there anything already written that does this type of thing? Try this out Brian: require 'timeout' class TooMuchTimeException < Exception;end class Class def time_limit(hash) hash.each do |name, limit| m = instance_method(name) define_method(name) do timeout(limit, TooMuchTimeException) do m.bind(self).call end end end end end class Foo def calc1 1 end def calc2 sleep(7) 2 end time_limit :calc1 => 20, :calc2 => 5 end f = Foo.new p f.calc1 p f.calc2