build2(args)
public
Synopsis
See ::new.
Description
At first, tries to create a new
URI::Generic instance using
URI::Generic::build. But, if exception URI::InvalidComponentError is
raised, then it does URI::Escape.escape all URI
components and tries again.
Show source
def self.build2(args)
begin
return self.build(args)
rescue InvalidComponentError
if args.kind_of?(Array)
return self.build(args.collect{|x|
if x.is_a?(String)
DEFAULT_PARSER.escape(x)
else
x
end
})
elsif args.kind_of?(Hash)
tmp = {}
args.each do |key, value|
tmp[key] = if value
DEFAULT_PARSER.escape(value)
else
value
end
end
return self.build(tmp)
end
end
end