Skip to content

Instantly share code, notes, and snippets.

@mindaslab
Last active August 29, 2015 14:19
Show Gist options
  • Save mindaslab/d6c8fe7e020f081b61a6 to your computer and use it in GitHub Desktop.
Save mindaslab/d6c8fe7e020f081b61a6 to your computer and use it in GitHub Desktop.
Primes in Ruby
class Fixnum
def prime?
return true if self == 1
2.upto(self) do |num|
if self % num == 0
return self == num
end
end
end
end
1.upto(100) do |num|
puts num if num.prime?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment