Skip to content

Instantly share code, notes, and snippets.

@jhsu
Created June 2, 2010 01:39
Show Gist options
  • Save jhsu/421799 to your computer and use it in GitHub Desktop.
Save jhsu/421799 to your computer and use it in GitHub Desktop.
# Find out if a number is prime
#
# Usage: 1.prime?
#
class Integer
def prime?
return false if self == 1
(2..(self-1)).each do |number|
return false if self % number == 0
end
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment