1
votes

I'm using:

  • Windows 7
  • Ruby 1.8.6 One-Click Installer
  • DBI version 0.4.3 installed using RubyGems

What I see when executing these commands:

C:>ruby -v

ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]

C:>gem -v

1.3.1

C:>ruby -r rubygems -r dbi -e "puts DBI::VERSION"

0.2.2

C:>gem list dbi

*** LOCAL GEMS ***

dbi (0.4.3)

C:>gem environment

RubyGems Environment:

  • RUBYGEMS VERSION: 1.3.1
  • RUBY VERSION: 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
  • INSTALLATION DIRECTORY: C:/Ruby/lib/ruby/gems/1.8
  • RUBY EXECUTABLE: C:/Ruby/bin/ruby.exe
  • EXECUTABLE DIRECTORY: C:/Ruby/bin
  • RUBYGEMS PLATFORMS:
    • ruby
    • x86-mswin32-60
  • GEM PATHS:
    • C:/Ruby/lib/ruby/gems/1.8
    • C:/Users/sutch/.gem/ruby/1.8
  • GEM CONFIGURATION:
    • :update_sources => true
    • :verbose => true
    • :benchmark => false
    • :backtrace => false
    • :bulk_threshold => 1000
  • REMOTE SOURCES:

Why do ruby scripts use the DBI installed in site_ruby rather than the DBI installed with RubyGems?


Update to respond to Luis Lavena's answer...

Here's what happened when I attempted what you suggest:

C:>ruby -r rubygems -e "require 'rubygems'; puts DBI::VERSION"

-e:1: uninitialized constant DBI (NameError)

And when I updated to require DBI:

C:>ruby -r rubygems -e "require 'rubygems' ; require 'dbi' ; puts DBI::VERSION"

0.2.2

Why wouldn't RubyGems override the built-in library?

1

1 Answers

0
votes

Using ruby -r you're using Ruby builtin require instead of the one redefined by RubyGems.

Try this:

ruby -r rubygems -e "require 'dbi'; puts DBI::VERSION"

That should do the trick.

FYI: this has been improved in newer versions of Ruby (1.9 versions, none of the 1.8 has this behavior).

Hope that helps.