Skip to content

Commit

Permalink
Fix NoMethodError error on Ruby 2.4 and older. Fixes kjvarga#352
Browse files Browse the repository at this point in the history
NoMethodError: private method `open' called for URI:Module was raised on older rubies as URI.open was added only in Ruby 2.5: https://rubyreferences.github.io/rubychanges/2.5.html#network-and-web
  • Loading branch information
Envek committed Jun 2, 2020
1 parent e650aa2 commit 459e90f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/sitemap_generator/link_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ def ping_search_engines(*args)
name = Utilities.titleize(engine.to_s)
begin
Timeout::timeout(10) {
URI.open(link)
if URI.respond_to?(:open) # Available since Ruby 2.5
URI.open(link)
else
open(link) # using Kernel#open became deprecated since Ruby 2.7. See https://bugs.ruby-lang.org/issues/15893
end
}
output(" Successful ping of #{name}")
rescue Timeout::Error, StandardError => e
Expand Down

0 comments on commit 459e90f

Please sign in to comment.