From: ahoward Date: 2003-01-12T05:43:40+09:00 Subject: Re: Timeout, delegation - request On Fri, 10 Jan 2003, Berger, Daniel wrote: [snip] > Please wrap standalone methods in their own modules! [snip] i agree with your reccomendation, but heres a hack fix... ----wrap.rb---- #!/usr/bin/env ruby class Module def wrap filename f = filename.strip absolute = (f[0] == File::SEPARATOR or f =~ /^[\w\d]+:/o) lines = nil errs = ["\n"] if absolute lines = IO.readlines f else #relative $:.each do |dir| path = File.join dir, f File.open (path) {|ios| lines = ios.gets nil } rescue errs << $! break if lines end end raise errs.join "\n" unless lines lines.gsub! (%r{def\s+(\w+)}o) do |match| method = $1 method =~ %r{^#{self}\.}o ? "def #{method}" : "def #{self}.#{method}" end module_eval lines end end module Timeout wrap 'timeout.rb' end Timeout::timeout nil do puts 'timeout wrapped' end module Foo wrap 'noexist.rb' end ----wrap.rb---- eg/ruby > wrap.rb timeout wrapped ../wrap.rb:18:in `wrap': (RuntimeError) No such file or directory - "/usr/local/lib/ruby/site_ruby/1.6/noexist.rb" No such file or directory - "/usr/local/lib/ruby/site_ruby/1.6/i686-linux/noexist.rb" No such file or directory - "/usr/local/lib/ruby/site_ruby/noexist.rb" No such file or directory - "/usr/local/lib/ruby/1.6/noexist.rb" No such file or directory - "/usr/local/lib/ruby/1.6/i686-linux/noexist.rb" No such file or directory - "./noexist.rb" from ./wrap.rb:38 -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================