Very simple problem, judging by this title.
- I have Ruby 1.9.2
- I installed Rake 0.9.2.2 with RubyGems (
gem install rake
) - I want to use Rake 0.9.2.2 in my Ruby environment (Rake 0.9.2.2 defines
Rake::DSL
module). How can I do ?
Simple answer (the one everyone is expecting to work):
1 2 | require 'rake' # => true Rake:: DSL # => NameError: uninitialized constant Rake::DSL |
=> Wrong
The problem here is that Ruby 1.9 comes already with Rake 0.8.7 in its standard library, and require will always give priority to standard library over installed gems. So whatever Rake version you may install on your system, require 'rake'
will always come up with version 0.8.7.
So basically, 2 solutions:
- Force Rake version using RubyGems:
123
gem
'rake'
,
'0.9.2.2'
# => true
require
'rake'
# => true
Rake::
DSL
# => Rake::DSL
- Include a rb file present in Rake 0.9.2.2 and unknown to 0.8.7, before requiring rake:
123
require
'rake/dsl_definition'
# => true
require
'rake'
# => true
Rake::
DSL
# => Rake::DSL
Hope this helps !