Skip to content

Instantly share code, notes, and snippets.

@imechemi
Created June 13, 2019 09:28
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 imechemi/e93e193cf92f9b8ddbb3489f9791b4f9 to your computer and use it in GitHub Desktop.
Save imechemi/e93e193cf92f9b8ddbb3489f9791b4f9 to your computer and use it in GitHub Desktop.
Object Oriented Prime Generator
class Prime
def initialize()
@value = 2
end
def value
@value
end
def next
i = @value
while true
i = i + 1
break if is_prime?(i)
end
@value = i
@value
end
private
def is_prime?(n)
(2..n/2).to_a.each do |divisor|
return false if n % divisor == 0
end
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment