1
說我有這樣的URL:http://www.rubinassociatespa.com/AccountantBocaRaton.html
如何在Ruby中使用URI類從域中提取根域?
我只想提取基本域 - http://www.rubinassociatespa.com
我無法弄清楚如何使用Ruby URI類,但是沒有做的字符串操作來做到這一點。
[36] pry(#<YPCrawler::PageParser>)> @url
=> "http://www.rubinassociatespa.com/AccountantBocaRaton.html"
[37] pry(#<YPCrawler::PageParser>)> URI(@url).scheme
=> "http"
[38] pry(#<YPCrawler::PageParser>)> URI(@url).host
=> "www.rubinassociatespa.com"
要使用字符串操作做到這一點,我將不得不做這樣的事情:
URI(@url).scheme + "://" + URI(@url).host
但似乎哈克。
是否有更「原生」的方式來做到這一點?一些很酷的方法或類似URI
類可以優雅地處理這個?
有沒有開箱即用的方法。 – Ilya