From: "Durant S." Date: 2007-06-22T08:52:21+09:00 Subject: Re: How do I intercept creation of fundatmental types, eg. [ Durant S. wrote: > ps - I figured out how to save and call Array.new below. Fortunately, > though I'm not sure why, this doesn't cause infinite recursion. > > > class Array > > @@count = 0 > > orig_new = %s{Array.new} > > def Array.new(*args,&block) > print "In Array.new" > print " with #{args.inspect}" if args > print " and #{block.inspect}" if block > print "\n" > print "\tself.class is #{self.class}\n" > @@count += 1 > puts "\tcount is now #{@@count}" > #super > orig_new(*args,&block) > end > > # ... > > end Sorry, that does not work ... I was inheriting an orig_new in "class Class" which is not shown here. This is what I had: class Class alias_method :orig_new, :new def new(*args,&block) result = orig_new(*args,&block) print "In Class.new" print " with #{args.inspect}" if args print " and #{block.inspect}" if block print "\n" print "\tresult.class is #{result.class}\n" result end end class Array @@count = 0 orig_new = %s{Array.new} def Array.new(*args,&block) print "In Array.new" print " with #{args.inspect}" if args print " and #{block.inspect}" if block print "\n" print "\tself.class is #{self.class}\n" @@count += 1 puts "\tcount is now #{@@count}" #super orig_new(*args,&block) end # ... end and I thought it was working... -- Posted via http://www.ruby-forum.com/.