'require' to fill $" with long names?

E

Erik Veenstra

Require fills $" with (the short names of) the library files it
is able to find. When the program has ended, RubyScript2Exe
tries to match the libraries in $" with the directories in $:
and the default extensions in order to collect the files. But,
since $: might change when running the program (RubyGems!...),
the files RubyScript2Exe finds are not necessarily the ones
Ruby finds.

I came up with this solution (see below). Just redefine require
before executing the application and $" will be filled with the
full names of the library files. Seems to work....

Any suggestions or considerations?

gegroet,
Erik V. - http://www.erikveen.dds.nl/

----------------------------------------------------------------

alias :eek:ld_require :require

def require(lib, *rest)
extensions = ["", ".rb", ".so", ".o", ".dll"]
search_list = $:.collect{|dir| extensions.collect{|ext|
File.expand_path(lib + ext, dir)}}.flatten
found = search_list.find{|file| File.file?(file)}
lib = found unless found.nil?

old_require(lib, *rest)
end

----------------------------------------------------------------
 
N

nobuyoshi nakada

Hi,

At Tue, 4 Oct 2005 00:41:47 +0900,
Erik Veenstra wrote in [ruby-talk:158842]:
I came up with this solution (see below). Just redefine require
before executing the application and $" will be filled with the
full names of the library files. Seems to work....

1.9 does so.
 
E

Erik Veenstra

I came up with this solution (see below). Just redefine
1.9 does so.

Quick check...

Well, uh, just partly. It does expand all pathes, except for
enumerator.so. Where does enumerator.so come from? Why isn't it
a full path?

Running on Cygwin on XP.

gegroet,
Erik V. - http://www.erikveen.dds.nl/

----------------------------------------------------------------

$ ./ruby.exe -v
ruby 1.9.0 (2005-10-04) [i386-cygwin]

$ ./ruby.exe -e 'p $"'
["enumerator.so"]

$ ./ruby.exe -r rbconfig -e 'p $"'
["enumerator.so", "/scratch/snapshot/ruby/rbconfig.rb"]

----------------------------------------------------------------
 
N

nobuyoshi nakada

Hi,

At Tue, 4 Oct 2005 21:41:48 +0900,
Erik Veenstra wrote in [ruby-talk:158980]:
Well, uh, just partly. It does expand all pathes, except for
enumerator.so. Where does enumerator.so come from? Why isn't it
a full path?

It is built-in now, and defined for backward compatibility
purpose.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top