Issue #6973 has been updated by jballanc (Joshua Ballanco).


Just a suggestion, but I don't think "integral" really explains what you want this method to do, and it is confusingly close to "integer?". Why not Numeric#whole_number?

Personally, I'm not entirely convinced this method is a good idea. With Floats, you can't really guarantee that "4.0" is the same as "4". It could actually be "4.00000000000000001" but the precision is lost. If you want to know if `my_float.floor == my_float`, that check isn't so hard to do and also has a very specific meaning. I could *maybe* see including this sort of method in BigDecimal or Rational (though in that case it would essentially be the same as `my_rational.denomenator == 1`). What sort of use case were you picturing?

Finally, just a note on the patch: there are easier (i.e. without allocation) ways to determine if a float, bigdecimal, or rational is a whole number. Why not give all of the subclasses in the stdlib specific implementations in addition to the generic implementation in Numeric?
----------------------------------------
Feature #6973: Add an #integral? method to Numeric to test for whole-number values
https://bugs.ruby-lang.org/issues/6973#change-29171

Author: regularfry (Alex Young)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 2.0.0


Numeric#integer? checks whether an instance is an Integer.  It is often useful to check whether the value of a non-Integer variable is actually a whole number, and the #integer? method doesn't help here.

This patch adds Numeric#integral?, which performs this check.


-- 
http://bugs.ruby-lang.org/