From: Harry Ohlsen Date: 2002-08-06T17:46:15+09:00 Subject: Writing a method that's added to both Fixnum and Bignum A mate of mine just asked me an interesting question. He had written a method that extended Fixnum and then realised that he wanted it to work for Bignum as well, but the code is obviously identical. The only way I could think of to do this was something like ... class Bignum def Bignum.fred(x) # Do the calculation with x end def fred Bignum.fred(self) end end class Fixnum def fred Bignum.fred(self) end end There HAS to be a better way to do it, but I just can't think of it. Effectively, what I would have thought it should be is something like ... class Bignum def fred # Do the calculation on self end end class Fixnum # Coerce self into a Bignum, say "b" and then return b.fred end But I can't think of how I would coerce the Fixnum into a Bignum.