merge(oth)
public
Args
Description
Merges two URI’s.
Usage
require 'uri'
uri = URI.parse("http://my.example.com")
p uri.merge("/main.rbx?page=1")
Show source
def merge(oth)
begin
base, rel = merge0(oth)
rescue
raise $!.class, $!.message
end
if base == rel
return base
end
authority = rel.userinfo || rel.host || rel.port
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)
if !authority
base.set_path(merge_path(base.path, rel.path)) if base.path && rel.path
else
base.set_path(rel.path) if rel.path
end
base.set_userinfo(rel.userinfo) if rel.userinfo
base.set_host(rel.host) if rel.host
base.set_port(rel.port) if rel.port
base.query = rel.query if rel.query
base.fragment=(rel.fragment) if rel.fragment
return base
end