Created
April 29, 2012 11:18
-
-
Save antimon2/2549532 to your computer and use it in GitHub Desktop.
add `each_from` method (`each` with lower_bound) in class Prime.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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