From: Joel VanderWerf Date: 2007-06-22T05:44:23+09:00 Subject: Re: How do I intercept creation of fundatmental types, eg. [] MenTaLguY wrote: > On Fri, 22 Jun 2007 05:28:24 +0900, "Durant S." wrote: >> For example, I can catch this: >> >> b = Array.new >> >> but I cannot catch this: >> >> x = [3,4,5] >> >> It seems like I should be able to do it with the awesome power of ruby >> :), but I can't figure out how. > > It isn't possible without modifying the interpreter; in the latter case, > the array is created directly by the interpreter, rather than via a method call. And there are other non-method sources of arrays: def mkary return 1,2,3 end GC.start p ObjectSpace.each_object(Array){} a = mkary p ObjectSpace.each_object(Array){} b = mkary p ObjectSpace.each_object(Array){} def mkary2(*args) args end c = mkary2 4,5,6 p ObjectSpace.each_object(Array){} d = mkary2 7,8,9 p ObjectSpace.each_object(Array){} GC.start p ObjectSpace.each_object(Array){} -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407