Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
URI::Generic#to_s
() -> ::String
to_s
lib/uri/generic.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/uri/generic.rb, line 1367
def to_s
str = ''.dup
if @scheme
str << @scheme
str << ':'
end
if @opaque
str << @opaque
else
if @host || %w[file postgres].include?(@scheme)
str << '//'
end
if self.userinfo
str << self.userinfo
str << '@'
end
if @host
str << @host
end
if @port && @port != self.default_port
str << ':'
str << @port.to_s
end
if (@host || @port) && !@path.empty? && !@path.start_with?('/')
str << '/'
end
str << @path
if @query
str << '?'
str << @query
end
end
if @fragment
str << '#'
str << @fragment
end
str
end