Integer Confusion

We have class Numeric, class Integer, class Fixnum, and class Bignum.
It seems that literal numbers are converted to objects of Fixnum/Bignum.
It also seems that Numeric/Integer are meant only for inheritance and
not instantiation, yet they aren't abstract classes. Is there a write-up
on all this, the basic intention, the details? I find the topic just
glossed over in the Pick-axe book.

Thanks.

Fixnums is for small C-style computer numbers. Bignums are for the totals that won't fit in a Fixnum, and Ruby will switch back and forth as needed.

Integer is a parent for both of the above, so it's the holder for shared behavior all integers should have.

Numeric is the root of ALL number classes, including Floats, again for shared behavior.

The only time I've ever needed to know that that I can remember is when I'm adding methods to one of them. If it's a method for integers, add it to Integer. Methods for all numbers belong in Numeric.

Hope that helps.

James Edward Gray II

···

On Sep 21, 2005, at 8:44 PM, Uncle Roastie wrote:

We have class Numeric, class Integer, class Fixnum, and class Bignum.
It seems that literal numbers are converted to objects of Fixnum/Bignum.
It also seems that Numeric/Integer are meant only for inheritance and
not instantiation, yet they aren't abstract classes. Is there a write-up
on all this, the basic intention, the details? I find the topic just
glossed over in the Pick-axe book.

Adding to James very comprehensible answer: Numeric and Integer are not abstract simply because there are no abstract classes in Ruby. (Ok, there are modules but in this case it doesn't fit the inheritance chain well and no other class is likely to have to mixin numeric functionality.)

Regards

    robert

···

Uncle Roastie <roastie@rochester.rr.com> wrote:

We have class Numeric, class Integer, class Fixnum, and class Bignum.
It seems that literal numbers are converted to objects of
Fixnum/Bignum. It also seems that Numeric/Integer are meant only for
inheritance and not instantiation, yet they aren't abstract classes. Is there a
write-up on all this, the basic intention, the details? I find the
topic just glossed over in the Pick-axe book.