Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top