Ruby Language Numbers

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

Numbers hierarchy

Ruby includes several built-in classes to represent numbers:

Numeric
  Integer
    Fixnum    # 1
    Bignum    # 10000000000000000000
  Float       # 1.0
  Complex     # (1+0i)
  Rational    # Rational(2, 3) == 2/3
  BigDecimal  # not loaded by default

The most common are:

  • Fixnum to represent, for instance positive and negative integers
  • Float to represent floating point numbers

BigDecimal is the only one not loaded by default. You can load it with:

require "bigdecimal"

Note that in ruby 2.4+, Fixnum and Bignum are unified; all integers are now just members of the Integer class. For backwards compatibility, Fixnum == Bignum == Integer.



Got any Ruby Language Question?