From: "T. Onoma" Date: 2003-11-22T10:22:03+09:00 Subject: Re: "stereotyping" and i thought it was so radical when i wrote it yesterday # notice if TypeErrors woud return offending respond_to? method # in error message then it would continue to probe class DuckHunter def initialize @a_r_g_s = {} end def a_r_g_s @a_r_g_s end def d_u_c_k_c_a_l_l begin yield rescue TypeError => e self.send(e.message) retry end end def method_missing(aSym, *args) # This will happen the first time aSymStr = aSym.to_s @a_r_g_s["#{aSymStr}"] = [ args.collect { |a| "#{a.class}" } ] begin d = %Q{ def self.#{aSymStr}(*args) # This will happen the subsequent time @a_r_g_s["#{aSymStr}"] } + %q{.concat [ args.collect { |a| "#{a.class}" } ] self end } instance_eval d rescue SyntaxError puts "TypeError induced SyntaxError! TypeError must return respond_to method!" raise end self end end # example class TypeTest def ameth(x) big4 x #--- puts x.to_i puts x.jump(4) puts x.do_what_ever("Duck can take it!", /\w+/) puts x.do_what_ever("Duck can take it!", /\w+/, 42) end end t = TypeTest.new puts "\nDUCK QUACKS" dh = DuckHunter.new dh.d_u_c_k_c_a_l_l do t.ameth(dh) end # show args puts "\nameth:" dh.a_r_g_s.each { |name, argpat| argpat.each { |args| puts "\t#{name} (#{args.join(',')})" } } # ----------- On Saturday 22 November 2003 12:52 am, Greg McIntyre wrote: > "David Naseby" wrote: > > Below is a quick hack to do that. Needs work. Needs redirection of IO. > > But its kinda cute.. Has issues with side effects, of course, and > > printing crapola all over the place. > > Is this or something like it on the RAA? Perhaps a slightly more general > mechanism to proxy messages to the "real" object and call a > hook/callback? late could be added