Anton Ipatov
Anton Ipatov

Reputation: 167

How to remove a double slash in ruby with URI method?

how to remove a double slash // in ruby with URI method?

2.4.1 :001 > URI('http://www.rbc.ru/society/23/11/2017/5a16ff0e9a7947e46d1e4957').tap { |uri| uri.query = nil; uri.scheme = nil }.to_s
 => "//www.rbc.ru/society/23/11/2017/5a16ff0e9a7947e46d1e4957"

Upvotes: 1

Views: 278

Answers (1)

tadman
tadman

Reputation: 211560

Just snip it off:

URI('...').to_s.sub(%r[\A//], '')

Doesn't have to be that complicated.

Upvotes: 3

Related Questions