Skip to content

Instantly share code, notes, and snippets.

@VoQn
Created January 26, 2011 19:02
Show Gist options
  • Save VoQn/797217 to your computer and use it in GitHub Desktop.
Save VoQn/797217 to your computer and use it in GitHub Desktop.
class Integer #Override
def prime? #boolean: itself is prime or not.
return true if self == 2
return false if self < 2 || self % 2 == 0
limit = Math::sqrt(self).ceil
(3..limit).step(2) { |i|
return false if self % i == 0
}
return true
end #prime?
end #Integer
#test
(1..100).map{ |i|
if i.prime?
puts i
end #if i.prime?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment