12345.class returning 'Integer' not 'Fixnum' in Ruby

Viewed 499

On the Ruby tutorials I'm watching when you enter a number with .class it returns either Bignum or Fixnum.

When I do this I get Integer instead:

12345.class
#=> Integer

I'm using irb in the command line on a mac. Why does the above not return Fixnum like it does in the tutorials?

2 Answers

You should get a better tutorial.

Ruby only guarantees that a class named Integer exists. It allows implementation-specific subclasses of Integer, and it mandates that if implementation-specific subclasses do exist, then Integer must be fully abstract, but it does not force those implementation-specific subclasses to exist.

I other words:

  • Integer always exists.
  • Implementation-specific subclasses of Integer may or may not exist.
  • Those implementation-specific subclasses may or may not be named Bignum and Fixnum.

The tutorial you are using is simply wrong (or at least outdated). This has been officially documented at least since the very first draft of the ISO Ruby Language Specification in 2009, but has been the case even before that.

Related