From: "duckinator (Nick Markwell)" Date: 2012-07-13T14:50:21+09:00 Subject: [ruby-core:46383] [ruby-trunk - Feature #3591] Adding Numeric#divisor? (Have working implementation) Issue #3591 has been updated by duckinator (Nick Markwell). Regarding Float, BigDecimal, Complex, and Rational: Agreed. Regarding `42 % 5 == 0`, I somewhat agree: it can be accomplished now, *and* it is not done often (excluding x % 2 == 0), so it may not be a good fit for core Ruby. When splitting it out so it does not cover things it does not apply to, it'd likely become more complex than it is worth dealing with. ---------------------------------------- Feature #3591: Adding Numeric#divisor? (Have working implementation) https://bugs.ruby-lang.org/issues/3591#change-27999 Author: duckinator (Nick Markwell) Status: Assigned Priority: Normal Assignee: mrkn (Kenta Murata) Category: Target version: =begin On the 'duckinator' branch of my fork of ruby on github, I have added Numeric#divisor?: num.divisor?(other) 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: http://gist.github.com/raw/484144/07b1a6e696cd9301e658ccbc8f90dfcd4d4ef3f1/Numeric_divisor.patch The original commits can be seen here: http://github.com/RockerMONO/ruby/commit/f7959f964cb0bf38418904ccb5643db6b689d29c -- First attempt, only worked with Integers http://github.com/RockerMONO/ruby/commit/12376a6bb1c3ffbd4b470850dd758e2dcd783dda -- Second attempt, should work with anything derived from Numeric that can be used as (num % other == 0) =end -- http://bugs.ruby-lang.org/