Skip to content

Instantly share code, notes, and snippets.

@antimon2
Created April 29, 2012 11:18
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 antimon2/2549532 to your computer and use it in GitHub Desktop.
Save antimon2/2549532 to your computer and use it in GitHub Desktop.
add `each_from` method (`each` with lower_bound) in class Prime.
require 'prime'
class Prime
def each_from lower_bound = 0, upper_bound = nil
return to_enum :each_from, lower_bound, upper_bound unless block_given?
if lower_bound.is_a? Range
range = lower_bound
lower_bound = range.first
upper_bound = range.exclude_end? ? range.last - 1 : range.last
end
flg = false
each upper_bound do |pr|
yield pr if flg ||= pr >= lower_bound
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment