I just wanted to understand for my self.

I'm using the nokogiri gem (for parsing HTML). If I got it right to open URLs I need to use a method from the gem 'open-uri'.

But when I include it in my Gemfile (on Windows developer's machine):

gem 'open-uri' - there is an error while bundle install that it can not find gem.

So If I use require 'open-uri' - its working.

So can some explain what is going on?

有帮助吗?

解决方案

You're using bundler for your gem dependecies and you're doing it right but OpenUri is part of the Ruby standard library. That's why you only need to require it if you want to use it in your code.

其他提示

require is used to load another file and execute all its statements. This serves to import all class and method definitions in the file. require also keeps track of which files have been previously required so it doesn't execute it twice.

A RubyGem is a software package, commonly called a “gem”. Gems contain a packaged Ruby application or library. The RubyGems software itself allows you to easily download, install, and manipulate gems on your system. - What is a Gem?:

The Gemfile is then used by bundler to install the specified gems.

open-uri is not a gem but part of the Ruby Standard Library so it just needs to be required.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top