From: oinkoink+unet@... (Bret Jolly) Date: 2003-05-04T15:34:13+09:00 Subject: Re: MathN oinkoink+unet@rexx.com (Bret Jolly) wrote in message news:<7e7131a1.0305031356.174fec7e@posting.google.com>... > If these conditions hold, I use klass.module_eval > to insert the definition in the class klass. That was pretty slick, wasn't it? Such slickness can produce inscrutable bugs. The last bit of code, which I meant to repeat but lost somehow, was this: ObjectSpace.each_object(Class) {|klass| if klass.ancestors.include?(Numeric) PlayNiceWithPnom.each{|key, value| if klass.public_instance_methods.include?(key) unless klass.public_instance_methods.include?("prePnom_#{value}") eval(%Q% klass.module_eval(PlayNiceWithPnom#{value})%) end end } end } I was just patting myself on the back for being so clever when I ran into a bug. This wasn't working properly for Bignum '>'. I investigated Bignum: irb(main):001:0> Bignum.public_instance_methods => ["**", "quo", "<=>", "-", "coerce", "==", "[]", "modulo", "|", "/", "size", "eql?", "<<", "%", ">>", "~", "&", "divmod", "to_s", "hash", "^", "abs", "to_f", "div", "*", "remainder", "+", "-@"] irb(main):002:0> Bignum.ancestors => [Bignum, Integer, Precision, Numeric, Comparable, Object, Kernel] Bignum gets its comparison methods >, <, >=, <= from Comparable via the spaceship <=>, so they weren't listed in Bignum.public_instance_methods, and my clever hack failed. I kluged my way around it, and now I'm trying to think of something better than a kluge. Regards, Bret