Dan Burton
Dan Burton

Reputation: 53665

Ruby uri parsing: "parent path"

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

Answers (1)

ichigolas
ichigolas

Reputation: 7725

Most simple way is:

File.dirname 'http://example.com/foo/bar/baz/quux/'
=> "http://example.com/foo/bar/baz"

Upvotes: 2

Related Questions