---
title: "Ruby 2.4 unifies Fixnum and Bignum into Integer"
description:
  "Ruby 2.4 has unified Fixnum and Bignum into Integer class. It has also
  deprecated usage of Fixnum and Bignum"
canonical_url: "https://www.bigbinary.com/blog/ruby-2-4-unifies-fixnum-and-bignum-into-integer"
markdown_url: "https://www.bigbinary.com/blog/ruby-2-4-unifies-fixnum-and-bignum-into-integer.md"
---

# Ruby 2.4 unifies Fixnum and Bignum into Integer

Ruby 2.4 has unified Fixnum and Bignum into Integer class. It has also
deprecated usage of Fixnum and Bignum

- Author: Prathamesh Sonpatki
- Published: November 18, 2016
- Categories: Ruby 2.4, Ruby

Ruby uses `Fixnum` class for representing small numbers and `Bignum` class for
big numbers.

```ruby
# 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 is `Bignum` or `Fixnum`. It's just an implementation detail.

Interestingly, Ruby also has `Integer` class which is superclass for `Fixnum`
and `Bignum`.

Starting with Ruby 2.4, Fixnum and Bignum
[are unified into Integer](https://bugs.ruby-lang.org/issues/12005).

```ruby
# Ruby 2.4

1.class         #=> Integer
(2 ** 62).class #=> Integer
```

Starting with Ruby 2.4 usage of Fixnum and Bignum constants
[is deprecated](https://bugs.ruby-lang.org/issues/12739).

```ruby
# Ruby 2.4

>> Fixnum
(irb):6: warning: constant ::Fixnum is deprecated
=> Integer

>> Bignum
(irb):7: warning: constant ::Bignum is deprecated
=> Integer
```

## How to know if a number is Fixnum, Bignum or 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
# Ruby 2.4

1.class #=> Integer

# Before Ruby 2.4
1.class #=> Fixnum
```

Look at [PR #25056](https://github.com/rails/rails/pull/25056) to see how Rails
is handling this case.

Similarly Arel is
[also supporting](https://github.com/rails/arel/commit/dc85a6e9c74942945ad696f5da4d82490a85b865)
both Ruby 2.4 and previous versions of Ruby.

## Links

- [Human page](https://www.bigbinary.com/blog/ruby-2-4-unifies-fixnum-and-bignum-into-integer)
