From: Brad Date: 2004-01-01T01:01:50+09:00 Subject: Re: Re: Overriding to_s ts wrote: > >>>>> "B" == Brad writes: > > B> I guess I was being a bit naive, I thought Numeric was a base class > B> for Integer, Float, etc. Is there any way to redefine to_s across > > Well, I've seen that I've said a stupidity : this is Fixnum which redefine > #to_s and not Integer > > Numeric is a base class for Fixnum and Float > > svg% ruby -e 'p Fixnum.ancestors; p Float.ancestors' > [Fixnum, Integer, Precision, Numeric, Comparable, Object, Kernel] > [Float, Precision, Numeric, Comparable, Object, Kernel] > svg% > > but these 2 classes re-define #to_s > > svg% ruby -e 'p Fixnum.instance_methods(false).grep(/to_s$/)' > ["to_s"] > svg% > > svg% ruby -e 'p Float.instance_methods(false).grep(/to_s$/)' > ["to_s"] > svg% > > svg% ruby -e 'p Integer.instance_methods(false).grep(/to_s/)' > [] > svg% > > svg% ruby -e 'p Numeric.instance_methods(false).grep(/to_s/)' > [] > svg% > > B> the board, i.e. for Integer, Float, etc without having to duplicate > B> code for each numeric type? > > wait for 2.0. I suspect that some persons will use wrapper to do this > (probably not its right use, I don't know ...) > > > Guy Decoux > > > > > Guy: Thanks again for the reply, I defined my own to_s for Fixnum and Float (aliasing original to_s) and this seems to be working for me. This should hold me over until Ruby 2.0 is released. :) Thanks, Brad