Created
October 8, 2008 14:29
-
-
Save tommorris/15524 to your computer and use it in GitHub Desktop.
A place where I put the stuff I reckon should go into Ruby Core
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fixnum | |
def divisible?(by) | |
if by.class == Array | |
self.divisible_by_all?(by) | |
elsif by.class == Range | |
self.divisible_by_all?(by.to_a) | |
elsif by.class == String | |
self.divisible?(by.to_i) | |
else | |
self.divmod(by)[1] == 0 | |
end | |
end | |
def divisible_by_all?(list) | |
list.delete_if{ |i| self.divisible?(i) }.empty? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment