Kit Ho Kit Ho - 3 months ago 10
Ruby Question

What is the difference between Integer and Fixnum?

I know that the

Fixnum
class inherits from the
Integer
class. But what is the actual difference between them? Are there any use cases where we sometimes use
Fixnum
, and sometimes use
Integer
instead?

Answer

You never "use" Integer. It is an abstract class whose job is to endow its children (Fixnum and Bignum) with methods. Under effectively no circumstances will you ever ask for an object's class and be told that it is an Integer.