This blog is part of our Ruby 2.4 series.
Prior to Ruby 2.4, Float and BigDecimal responded to methods infinite? and
finite?, whereas Fixnum and Bignum did not.
#infinite?
5.0.infinite?
=> nil
Float::INFINITY.infinite?
=> 1
5.infinite?
NoMethodError: undefined method `infinite?' for 5:Fixnum
#finite?
5.0.finite?
=> true
5.finite?
NoMethodError: undefined method `finite?' for 5:Fixnum
To make behavior for all the numeric values to be consistent, infinite? and finite? were added to Fixnum and Bignum even though they would always return nil.
This gives us ability to call these methods irrespective of whether they are simple numbers or floating numbers.
#infinite?
5.0.infinite?
=> nil
Float::INFINITY.infinite?
=> 1
5.infinite?
=> nil
#finite?
5.0.finite?
=> true
5.finite?
=> true

Written byAbhishek Jain
Related blogs
- 01Ruby 2.4 has optimized enumerable min max methodsSeptember 28, 2017 · Chirag Shah
- 02CSV::Row#each etc. return enumerator when no block givenSeptember 25, 2017 · Sushant Mittal
- 03Ruby 2.4 DateTime#to_time & Time#to_time keeps infoSeptember 19, 2017 · Sushant Mittal
- 04Avoid exception for dup on IntegerAugust 1, 2017 · Rohit Arolkar