In Ruby 3.0.0 and later versions, the escape method in the URI module has been removed, leading to the error "undefined method escape' for URI:Module" 1. To address this issue, you can switch to using CGI.escape as an alternative to URI.escape. The reason for this change is that the escape method in the URI module was deprecated and removed intentionally .
Here is how you can update your code to use CGI.escape instead of URI.escape:
require 'cgi'
uri = URI(uri + path + "?q=" + CGI.escape(term))
By replacing URI.escape with CGI.escape, you ensure compatibility with Ruby 3.0.0 and above. This change aligns with the recommendation to use CGI.escape, URI.encode_www_form, or URI.encode_www_form_component depending on your specific use case .
Using CGI.escape provides a suitable alternative for encoding URI components and ensures your code remains functional across different Ruby versions.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
In Ruby 3.0.0 and later versions, the
escapemethod in the URI module has been removed, leading to the error "undefined method escape' for URI:Module" 1. To address this issue, you can switch to usingCGI.escapeas an alternative toURI.escape. The reason for this change is that theescapemethod in theURImodule was deprecated and removed intentionally .Here is how you can update your code to use
CGI.escapeinstead ofURI.escape:By replacing
URI.escapewithCGI.escape, you ensure compatibility with Ruby 3.0.0 and above. This change aligns with the recommendation to useCGI.escape,URI.encode_www_form, orURI.encode_www_form_componentdepending on your specific use case .Using
CGI.escapeprovides a suitable alternative for encoding URI components and ensures your code remains functional across different Ruby versions.Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.