Irb: require returns false?

hey everyone (ruby n00b here),

I am trying to compile ruby 1.8.6-p287. I built it using:

./configure --prefix=/usr/local/ruby --enable-pthread --enable-shared

I was playing with how support for things like iconv, gdbm, openssl, etc
worked and did:

irb(main):001:0> require ‘gdbm’
LoadError: no such file to load – gdbm
from (irb):1:in `require’
from (irb):1

so I installed the gdbm devel libs, and did recompiled. Now I get:

irb(main):004:0> require ‘gdbm’
=> false

When I use Redhats stock 1.8.5 rpm, I get:

irb(main):001:0> require ‘gdbm’
=> true

So my question is… what does “false” mean? The first time I tried, it
complained about not being able to load the file. After installing the
devel package, it now just says false. Does this mean that it properly
loading it but just not enabling it somehow?

Can someone shed some light on this for me?

Thanks!

Alle Wednesday 31 December 2008, Mike Carbs ha scritto:

LoadError: no such file to load – gdbm
irb(main):001:0> require ‘gdbm’
=> true

So my question is… what does “false” mean? The first time I tried, it
complained about not being able to load the file. After installing the
devel package, it now just says false. Does this mean that it properly
loading it but just not enabling it somehow?

Can someone shed some light on this for me?

Thanks!

require returns false if the given file had already been loaded. For
example:

require ‘singleton’
=> true
require ‘singleton’
=> false

The second time, the ‘singleton’ feature has already been loaded (by the
first
require), so there’s no need to load that again and require tells you
that by
returning false. You can see which features have already been loaded by
inspecting the global variable $". For my irb session, this is the
result:

p $"
=> [“enumerator.so”, “rubygems/rubygems_version.rb”,
“rubygems/defaults.rb”,
“thread.so”, “thread.rb”, “rbconfig.rb”, “rubygems/exceptions.rb”,
“rubygems/requirement.rb”, “rubygems/version.rb”,
“rubygems/dependency.rb”,
“rubygems/gem_path_searcher.rb”, “rubygems/user_interaction.rb”,
“rubygems/platform.rb”, “rubygems/specification.rb”,
“rubygems/source_index.rb”, “rubygems/builder.rb”, “stringio.so”,
“yaml/error.rb”, “syck.so”, “yaml/ypath.rb”, “yaml/basenode.rb”,
“yaml/syck.rb”, “yaml/tag.rb”, “yaml/stream.rb”, “yaml/constants.rb”,
“rational.rb”, “date/format.rb”, “date.rb”, “yaml/rubytypes.rb”,
“yaml/types.rb”, “yaml.rb”, “rubygems/config_file.rb”,
“rubygems/custom_require.rb”, “rubygems.rb”, “auto_gem.rb”, “e2mmap.rb”,
“irb/init.rb”, “irb/workspace.rb”, “irb/context.rb”,
“irb/extend-command.rb”,
“irb/output-method.rb”, “irb/notifier.rb”, “irb/slex.rb”,
“irb/ruby-token.rb”,
“irb/ruby-lex.rb”, “readline.so”, “irb/input-method.rb”,
“irb/locale.rb”,
“irb.rb”, “irb/completion.rb”, “irb/ext/save-history.rb”,
“singleton.rb”]

Calling require with one of these features will return false, because
they’ve
already been loaded.

What is important is to understand that the return value of require
never
means that an error has occurred. If an error occurs, you’ll get an
exception,
as it happened to you when calling require ‘gdbm’ the first time.

I hope this helps

Stefano

When require returns false it means that the library has already been
required.
(At least I don’t know any other case…)

LoadError: no such file to load – gdbm
irb(main):001:0> require ‘gdbm’

Posted via http://www.ruby-forum.com/.


“Configure complete, now type ‘make’ and PRAY.”

            (configure script of zsnes - www.zsnes.com)