From: Vadim Nasardinov Date: 2004-04-08T00:29:26+09:00 Subject: defadvice in Ruby? (was: Re: deciding between ruby and python) On Wednesday 07 April 2004 02:09, gabriele renzi wrote: > >Nope. > > yep > just look at you own output. ... > guess why you can't use a prime? because you can't pause the yielding. > You're forced to use the whole number of Prime number that are > actually.. infinite. > So, you discover that you can't zip it cause zip calls to_ary. It occurred to me that it would be useful to be able to trace all messages sent to an object in order to figure out how the object is used. So, for example, I would like to be able to see all messages sent to baz when it's zipped with foo like so: foo.zip(baz) I found tracer.rb in the Ruby library, but it seems to have been written for a different purpose. I'm thinking of something similar to this: #!/usr/bin/ruby class Tracer < Array Tracer.new.methods.each do |mm| undef_method mm unless mm == "__send__" end def initialize(proxied_object, name) @proxied_object = proxied_object @name = name end def method_missing(sym, *args) puts "#{sym} called for #{name}" @proxied_object.method(sym).call(*args) end end a = Tracer.new([1,2,3,4,5], "a") b = Tracer.new([6,7,8,9,10], "b") a.zip(b) It almost looks like it should work. Unfortunately, this script causes my Ruby interpreter to segfault. (I'm using Ruby 1.8.0 that ships with Fedora Core 1.) So, I guess my two questions are: (a) Has anyone written something like this already? (b) What does the above segfault on me? Thanks, Vadim P.S. I googled for http://www.google.com/search?q=defadvice+Ruby but nothing jumped out at me.