Feature #3591

Updated by mame (Yusuke Endoh) almost 8 years ago


On the 'duckinator' branch of my fork of ruby on github, I have added Numeric#divisor?:
is the same as:
(num % other == 0)

Example usage:
4.divisor?(2) #=> true
1.divisor?(2) #=> false
2.4.divisor?(1.2) #=> true
2.4.divisor?(1.3) #=> false
126.divisor?(9) #=> true

I think this would be a very nice feature to add, and would make code using the old (num % other == 0) method much cleaner and easier to understand.

There is a unified diff of it:

The original commits can be seen here: -- First attempt, only worked with Integers -- Second attempt, should work with anything derived from Numeric that can be used as (num % other == 0)