Ruby的'open-uri'和'Net:HTTP'宝石之间有什么区别? [英] What is the difference between Ruby's 'open-uri' and 'Net:HTTP' gems?

查看:155
本文介绍了Ruby的'open-uri'和'Net:HTTP'宝石之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎这两个宝石都执行非常类似的任务。任何人都可以举出一个宝石比另一个更有用的例子吗?我没有具体的代码,我更关心每个宝石的一般用例。我知道这是一个简短的问题,我会根据要求填补空白。感谢。

解决方案

OpenURI是Net :: HTTP的一个包装器,Net :: HTTPS和Net :: FTP。通常,除非您觉得您需要更低级别的界面,否则使用OpenURI更好,因为您可以用更少的代码获得更好的效果。使用OpenURI你可以打开一个URL / URI并把它当作一个文件。



请参阅: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/open-uri/rdoc/ OpenURI.html
http://ruby-doc.org/stdlib-1.9.3//libdoc/net/http/rdoc/Net.html


It seems like both of these gems perform very similar tasks. Can anyone give examples of where one gem would be more useful than the other? I don't have specific code that I'm referring to, I'm more wondering about general use cases for each gem. I know this is a short question, I will fill in the blanks upon request. Thanks.

解决方案

The reason they look like they perform similar tasks is OpenURI is a wrapper for Net::HTTP, Net::HTTPS, and Net::FTP.

Usually, unless you feel you need a lower level interface, using OpenURI is better as you can get by with less code. Using OpenURI you can open a URL/URI and treat it as a file.

See: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/open-uri/rdoc/OpenURI.html and http://ruby-doc.org/stdlib-1.9.3//libdoc/net/http/rdoc/Net.html

这篇关于Ruby的'open-uri'和'Net:HTTP'宝石之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆