Skip to content

Instantly share code, notes, and snippets.

@abonec
Last active August 29, 2015 14:11
Show Gist options
  • Save abonec/836dfe35241b03b1dacf to your computer and use it in GitHub Desktop.
Save abonec/836dfe35241b03b1dacf to your computer and use it in GitHub Desktop.
def iterate_over_pages pattern
page = 1
loop do
url = pattern.gsub(/%page%/, page.to_s)
break unless yield url, page
page += 1
end
end
iterate_over_pages("http://leplay.com.ua/category/pic/page/%page%/") do |url, page|
puts url
4.times do |i|
puts i
if page == 3 && i == 3
break
end
end
end
@psylone
Copy link

psylone commented Dec 15, 2014

def iter_over_pages url
  loop do
    result = yield url
    result ? url.next! : break
  end

end

iter_over_pages("http://leplay.com.ua/category/pic/page/1/") do |url|
  10.times do |i|
    p i
    break if url.match(/(\d+)\/$/)[1].to_i == 10 && i == 4
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment