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.set_fragment(rel.fragment) if rel.fragment
return base
end
base.set_query(nil)
base.set_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.set_query(rel.query) if rel.query
base.set_fragment(rel.fragment) if rel.fragment
return base
end