Here is a snippet from a Sinatra app where users will be submitting urls. I must ensure that http:// is prepended to the url in order to route outside my application. How can I state site once and access it’s attributes? (Line 3)
p.params= "www.ruby-lang.org/en/"
site = URI(p.params[:url])
site = "http://" + site.host + site.path + site.query
If you need to ensure the url begins with
http://, why not use a regex?^(?!http:\/\/)matches only when the beginning of the string is not followed byhttp://