From: Nikolai Weibull Date: 2009-10-22T17:25:09+09:00 Subject: [ruby-core:26226] Re: Config.datadir in 1.9.1 On Thu, Oct 22, 2009 at 04:55, Yugui wrote: > 2009/10/21 Nikolai Weibull : >> In 1.8.6., Config.datadir('package') would give you the gem-relative >> data directory for a gem. ��In 1.9.1, Config doesn���t seem to even be >> loaded at startup. ��What happened? ��What am I supposed to use instead? >> ��Even if you get Config loaded it still won���t work, as the gem���s paths >> are already added to $LOAD_PATH, so Rubygems won���t load the >> specification and thus Gem.datadir('package') will give a nil result. > First, ::Config is deprecated. You should use RbConfig instead. > ::Config is an alias of RbConfig for compatibility to < 1.8. > > Second, RbConfig is a bundled library but not a core library. So it is > not loaded by default. > I think it has been loaded by RubyGems when you use RubyGems. > > Third, RbConfig.datadir(pkg) is a part of RubyGems but not a part of RbConfig. > > So you should write like this: > > ��require 'rbconfig' > ��require 'rbconfig/datadir' > > ��RbConfig.datadir("blahblahblah") > > This works fine for both 1.8 and 1.9. Well, actually it doesn���t work. I mean, yes, the function is there, but the problem is that it doesn���t return the correct path. Let me clear this up a bit. Assume that expectations-1.2.1 is installed for both 1.8 and 1.9.1. In 1.8.6, with RUBYOPT="-rubygems", I could simply start up irb and the following would happen: % irb irb(main):001:0> require 'expectations' => true irb(main):002:0> Config.datadir('expectations') => "C:/Ruby18/lib/ruby/gems/1.8/gems/expectations-1.2.1/data/expectations" but on 1.9.1 that isn���t as straightforward. Fine, we���ll do the following instead: % irb irb(main):001:0> require 'expectations' => true irb(main):002:0> require 'rbconfig' => true irb(main):003:0> require 'rbconfig/datadir' => true irb(main):004:0> RbConfig.datadir('expectations') => "C:/Ruby19/share/expectations" OK, so Rubygems isn���t loaded automatically and can thus not override RbConfig.datadir. What we need to do seems to be % irb irb(main):001:0> require 'expectations' => true irb(main):002:0> Gem.datadir('expectations') => nil irb(main):003:0> gem 'expectations' => true irb(main):004:0> RbConfig.datadir('expectations') => "C:/Ruby19/lib/ruby/gems/1.9.1/gems/expectations-1.2.1/data/expectations" and that, my friends, is insane. The Gem.datadir('expectations') seems to be needed to get the gem 'expectations' to actually do anything (it returns false if the Gem.datadir('expectations') doesn���t appear before it). I���m guessing that that line loads up Rubygems, because a require 'rubygems' sure doesn���t. So instead of Rubygems being transparently integrated into Ruby 1.9.1, what I���ve got now is an incredible mess where I need to force Rubygems to rear its ugly head all over the place.