Difference between gem and require (require open-uri) Difference between gem and require (require open-uri) ruby ruby

Difference between gem and require (require open-uri)


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.