We write about Ruby on Rails, React.js, React Native, remote work, open source, engineering and design.
for representing small numbers
for big numbers.
# Before Ruby 2.4 1.class #=> Fixnum (2 ** 62).class #=> Bignum
In general routine work
we don't have to worry about
whether the number we are dealing with
It's just an implementation detail.
Ruby also has
which is superclass
Starting with Ruby 2.4, Fixnum and Bignum are unified into Integer.
# Ruby 2.4 1.class #=> Integer (2 ** 62).class #=> Integer
Starting with Ruby 2.4 usage of Fixnum and Bignum constants is deprecated.
# Ruby 2.4 >> Fixnum (irb):6: warning: constant ::Fixnum is deprecated => Integer >> Bignum (irb):7: warning: constant ::Bignum is deprecated => Integer
We don't have to worry about this change most of the times in our application code. But libraries like Rails use the class of numbers for taking certain decisions. These libraries need to support both Ruby 2.4 and previous versions of Ruby.
Easiest way to know whether the Ruby version is using integer unification or not is to check class of 1.
# Ruby 2.4 1.class #=> Integer # Before Ruby 2.4 1.class #=> Fixnum
Look at PR #25056 to see how Rails is handling this case.
Similarly Arel is also supporting both Ruby 2.4 and previous versions of Ruby.