Skip to content

Instantly share code, notes, and snippets.

@tommorris
Created October 8, 2008 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommorris/15524 to your computer and use it in GitHub Desktop.
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
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