class

Prime

v1_8_7_72 - Show latest stable - Superclass: Object

No documentation available for this class.

Included modules

  • Enumerable

Files

  • lib/mathn.rb

1Note

Cheking if a number is prime?

Alex ยท Aug 15, 20084 thanks

It's a class for generating an enumerator for prime numbers and traversing over them.

It's really slow and will be replaced in ruby 1.9 with a faster one.

Note: if you just want to test whether a number is prime or not, you can use this piece of code:

class Fixnum
def prime?
  ('1' * self) !~ /^1?$|^(11+?)\\1+$/
end
end

10.prime?