How to set, require and use a ruby โ€‹โ€‹gem

I am trying to use rakein my ruby โ€‹โ€‹script ... (Ruby 1.8.6, JRuby 1.6.5)

A loaded rake using gem install --remote rake, looks normal during installation ...

Fetching: rake-0.9.2.2.gem (100%)
Successfully installed rake-0.9.2.2
1 gem installed

I have a simple ruby โ€‹โ€‹script that works fine, but when I import raketo use any of the following requires, it starts complaining ....

require 'rake'
LoadError: no such file to load -- rake
  or
require '/lib/rake'
LoadError: no such file to load -- lib/rake

After some searching, I found that adding require 'rubygems'just before rakefixes the problem ....

require 'rubygems'
require 'rake'

Despite the fact that it works, I have some questions ...

  • The gem specification doesn't rakeshow require_pathhow lib, so why doesn't it work require '/lib/rake'? Do I not understand the meaning require_path?

  • require 'rubygems' require 'rake'

+3
2

, . require_paths gem, , .

, , :

 $ gem which rake

, - /lib; /var/lib/gems. Ruby gems, , ; Ruby include path ($:) rubygems, require, . ( Ruby 1.9, .)

, ; , , , , Ruby include.

+5
  • require_path gemspec ruby, . require 'rake', ruby โ€‹โ€‹, /lib/rake gem.
  • Ruby 1.8 (, , ) , - . rubygems, . Ruby 1.9 .
+1

All Articles