Search code examples
rubyrubygemsrequire

require 'rubygems'


I have seen many samples of Ruby code with this line (for example, http://www.sinatrarb.com/). What is purpose of this require?

# require 'rubygems'
require 'sinatra'
get '/hi' do
  "Hello world!"
end

In all cases the code works without this line.


Solution

  • It is often superfluous. It will allow you to require specific versions of particular gems though, with the gem command.

    https://guides.rubygems.org/patterns/#requiring-rubygems