instance method
URI::Generic#merge
(::URI::Generic | ::string oth) -> ::URI::Generic
merge(oth)
lib/uri/generic.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/uri/generic.rb, line 1124
def merge(oth)
rel = parser.__send__(:convert_to_uri, oth)
if rel.absolute?
#raise BadURIError, "both URI are absolute" if absolute?
# hmm... should return oth for usability?
return rel
end
unless self.absolute?
raise BadURIError, "both URI are relative"
end
base = self.dup
authority = rel.authority
# RFC2396, Section 5.2, 2)
if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query
base.fragment=(rel.fragment) if rel.fragment
return base
end
base.query = nil
base.fragment=(nil)
# RFC2396, Section 5.2, 4)
if authority
base.set_authority(*authority)
base.set_path(rel.path)
elsif base.path && rel.path
base.set_path(merge_path(base.path, rel.path))
end
# RFC2396, Section 5.2, 7)
base.query = rel.query if rel.query
base.fragment=(rel.fragment) if rel.fragment
return base
end
Args
Description
Merges two URIs.
Usage
Example
require 'uri' uri = URI.parse("http://my.example.com") uri.merge("/main.rbx?page=1") # => "http://my.example.com/main.rbx?page=1"