Reputation: 53665
I have a URI of the form "http://example.com/foo/bar/baz/quux/". I want to retrieve "http://example.com/foo/bar/baz/". In other words, I want to drop the final segment of the path. What is the idiomatic Ruby way to do this? With a URI library? Or do I just have to write up the string parsing myself?
Upvotes: 1
Views: 280
Reputation: 7725
Most simple way is:
File.dirname 'http://example.com/foo/bar/baz/quux/'
=> "http://example.com/foo/bar/baz"
Upvotes: 2