How to get an absolute address of a link

Is there some URL lib that I can use to get the absolute address of a
relative URL ? Maybe I could pass a “base” link to the method . Ideally
, I would like to know if this could by achieved from mechanize , but
anything would do .
I wrote my own a while back , and I’m using it , but I would like to
know if something already exists .

On Wed, Jan 28, 2009 at 9:30 AM, Tsunami S. [email protected]
wrote:

Is there some URL lib that I can use to get the absolute address of a
relative URL ? Maybe I could pass a “base” link to the method . Ideally
, I would like to know if this could by achieved from mechanize , but
anything would do .

You can use URI.join

irb -ruri
irb(main):001:0> URI.join(‘http://example.com’, ‘/path/a/b’)
=> #<URI::HTTP:0xb7ce2b08 URL:http://example.com/path/a/b>
irb(main):002:0> URI.join(‘http://example.com’,
http://google.com/path/a/b’)
=> #<URI::HTTP:0xb7cdf28c URL:http://google.com/path/a/b>
irb(main):003:0>

Very nice ! Thanks ! I was wondering if it would handle joins with
arguments like

arg1 = “http://site.com
arg2 = “index.html”

or arg1 = “http://site.com/
arg2 = “/index.html”

and it seems to work great . Thank you !