# \[ANN\] RubyScript2Exe 0.2.0

**URL:** <https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204>\
**Category:** ruby-talk\
**Created:** [8 December 2004 13:47 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204 "2004-12-08T13:47:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik\_Veenstra3](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@Erik\_Veenstra3](https://rubytalk.org/u/Erik_Veenstra3)\
**Post date:** [8 December 2004 13:47 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/1 "2004-12-08T13:47:30Z")

</div>

I just want to say that RubyScript2Exe 0.2.0 [1] has been  
released. Both Windows and Linux are supported.

gegroet,  
Erik V.

[1] [http://www.erikveen.dds.nl/rubyscript2exe/index.html](http://www.erikveen.dds.nl/rubyscript2exe/index.html)

> **···**
>
> ----------------------------------------------------------------
> 
> RubyScript2Exe transforms your Ruby script into a standalone  
> Windows or Linux executable. You can look at it as a  
> "compiler". Not in the sense of a source-code-to-byte-code  
> compiler, but as a "collector", for it collects all necessary  
> files to run your script on an other machine: the Ruby script,  
> the Ruby interpreter and the Ruby runtime library (stripped  
> down for this script). Anyway, the result is the same: a  
> standalone exe-file (Windows) or bin-file (Linux). And that's  
> what we want!
> 
> Because of the gathering of files from your own Ruby  
> installation, RubyScript2Exe creates an executable for the  
> platform it's being run on. No cross compile.
> 
> And when I say Windows, I mean both Windows (RubyInstaller,  
> MinGW and MSWin32) and Cygwin. But the generated exe under  
> Cygwin is very, very big, because its exe's are very big  
> (static?) and it includes cygwin1.dll, so it can run on  
> machines without Cygwin.
> 
> ----------------------------------------------------------------

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [8 December 2004 14:17 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/2 "2004-12-08T14:17:34Z")

</div>

Erik Veenstra wrote:

> I just want to say that RubyScript2Exe 0.2.0 [1] has been released. Both Windows and Linux are supported.

Is a change list available somewhere? I couldn't find one on the homepage.

Also while I'm writing to you, would it be possible to allow custom ..DLLs and resources to be added? I have an application that uses a C++ extension which loads more .DLLs -- RubyScript2Exe does not automatically include those and I can't find a way of manually including them that works. (I can unpack and repackage, but then the .DLLs will still not get loaded from the temporary directory.)

Being able to easily include own media would also be very nifty in my use case. (I'm writing games with Ruby -- it's always nice to have a single EXE distribution that contains all the game media.)

Thank you for a great library!

---

<div class="post-metadata">

**Author:** ![Its\_Me](https://avatars.discourse-cdn.com/v4/letter/i/958977/32.png) [@Its\_Me](https://rubytalk.org/u/Its_Me)\
**Post date:** [8 December 2004 14:47 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/3 "2004-12-08T14:47:34Z")

</div>

"Erik Veenstra" \<pan@erikveen.dds.nl\> wrote in message

> I just want to say that RubyScript2Exe 0.2.0 [1] has been  
> released. Both Windows and Linux are supported.

Will this support all manner of 'require'd files, including those loaded by  
the gems require-hack?

Thanks!

---

<div class="post-metadata">

**Author:** ![Erik\_Veenstra3](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@Erik\_Veenstra3](https://rubytalk.org/u/Erik_Veenstra3)\
**Post date:** [8 December 2004 14:42 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/4 "2004-12-08T14:42:30Z")

</div>

> Erik Veenstra wrote:
> 
> \> I just want to say that RubyScript2Exe 0.2.0 [1] has been  
> \> released. Both Windows and Linux are supported.
> 
> Is a change list available somewhere? I couldn't find one on  
> the homepage.

It's there, really... The Download section [1] has a link to  
both [2] and [3]. I think you are interested in [2].

> Also while I'm writing to you, would it be possible to allow  
> custom .DLLs and resources to be added? I have an application  
> that uses a C++ extension which loads more .DLLs --  
> RubyScript2Exe does not automatically include those and I  
> can't find a way of manually including them that works. (I  
> can unpack and repackage, but then the .DLLs will still not  
> get loaded from the temporary directory.)

There's a link to Tar2RubyScript [4] on the page as well.  
Tar2RubyScript generates a standalone Ruby script from an  
existing directory, which contains a complete Ruby application  
(scripts, DLL's and resources). This standalone Ruby script can  
be converted to an executable with RubyScript2Exe.

That's how I distribute all my applications, complete with  
resources, help files, licenses, readme, images, default  
configurations, everything. Even including the graphical front  
end (WXRuby or RubyWebDialogs [5]). And it just works...

> Being able to easily include own media would also be very  
> nifty in my use case. (I'm writing games with Ruby -- it's  
> always nice to have a single EXE distribution that contains  
> all the game media.)
> 
> Thank you for a great library!

[1] [http://www.erikveen.dds.nl/rubyscript2exe/index.html#6..Download](http://www.erikveen.dds.nl/rubyscript2exe/index.html#6..Download)  
[2] [http://www.erikveen.dds.nl/rubyscript2exe/download.html](http://www.erikveen.dds.nl/rubyscript2exe/download.html)  
[3] [http://www.erikveen.dds.nl/rubyscript2exe/history.txt.html](http://www.erikveen.dds.nl/rubyscript2exe/history.txt.html)  
[4] [Tar2RubyScript - A Tool for Distributing Ruby Applications](http://www.erikveen.dds.nl/tar2rubyscript/index.html)  
[5] [http://www.erikveen.dds.nl/rubywebdialogs/index.html](http://www.erikveen.dds.nl/rubywebdialogs/index.html)

> **···**
>
> On Wed, 08 Dec 2004 15:16:02 +0100, Florian Gross wrote:

---

<div class="post-metadata">

**Author:** ![Erik\_Veenstra3](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@Erik\_Veenstra3](https://rubytalk.org/u/Erik_Veenstra3)\
**Post date:** [8 December 2004 15:47 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/5 "2004-12-08T15:47:29Z")

</div>

> "Erik Veenstra" \<pan@erikveen.dds.nl\> wrote in message
> 
> \> I just want to say that RubyScript2Exe 0.2.0 [1] has been  
> \> released. Both Windows and Linux are supported.
> 
> Will this support all manner of 'require'd files, including  
> those loaded by the gems require-hack?

Never worked with gems before...

I did a test (on Linux) with the progressbar example. Yes,  
RubyScript2Exe detects progressbar.rb [1] and yes, it is  
included in the executable [2]. But when the executable is run,  
require\_gem only searches for progressbar.rb in its own dirs,  
not in the regular places. Resulting in an Gem::LoadError. If I  
catch this exception, it does work. See below.

I'll have a look at it.

Thanks.

gegroet,  
Erik V.

[1] /usr/local/lib/ruby/gems/1.8/gems/progressbar-0.0.3/lib/progressbar.rb  
[2] ./lib/progressbar.rb

> **···**
>
> ----------------------------------------------------------------
> 
> Development machine:
> 
> [erik@devel]$ ruby rubyscript2exe.rb testgem.rb  
> Tracing testgem...  
> Gathering files...% |oooooooooooooooooooooooooooooooooooooooo| ETA: 00:00:00  
> Copying files...  
> Copying /lib/ld-linux.so.2 ...  
> Copying /usr/local/bin/ruby ...  
> Copying /scratch/testgem.rb ...  
> Creating testgem.bin ...
> 
> Test machine:
> 
> [erik@test1]$ ./testgem.bin  
> Example progr: 100% |oooooooooooooooooooooooooooooooooooooooo| ETA: 00:00:00
> 
> ----------------------------------------------------------------
> 
> # Doesn't work.
> 
> require 'rubygems'  
> require\_gem 'progressbar'
> 
> ----------------------------------------------------------------
> 
> # Does work.
> 
> require 'rubygems'  
> begin  
> &nbsp;&nbsp;&nbsp;require\_gem 'progressbar'  
> rescue Gem::LoadError  
> &nbsp;&nbsp;&nbsp;require 'progressbar'  
> end
> 
> ----------------------------------------------------------------

---

<div class="post-metadata">

**Author:** ![Steven\_Todd\_Harris](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Steven\_Todd\_Harris](https://rubytalk.org/u/Steven_Todd_Harris)\
**Post date:** [10 December 2004 23:22 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/6 "2004-12-10T23:22:25Z")

</div>

This sounds cool. Anyone know what it would take to have this for OS X?  
It would be cool to be able to use RubyCocoa or TKRuby or QTRuby and  
then  
make it into an executable easily.

Florian Gross wrote:

> Erik Veenstra wrote:
> 
> \> I just want to say that RubyScript2Exe 0.2.0 [1] has been  
> \> released. Both Windows and Linux are supported.
> 
> Is a change list available somewhere? I couldn't find one on the

homepage.

> Also while I'm writing to you, would it be possible to allow custom  
> .DLLs and resources to be added? I have an application that uses a

C++

> extension which loads more .DLLs -- RubyScript2Exe does not  
> automatically include those and I can't find a way of manually

including

> **···**
>
> > them that works. (I can unpack and repackage, but then the .DLLs will
> 
> > still not get loaded from the temporary directory.)
> > 
> > Being able to easily include own media would also be very nifty in my
> 
> > use case. (I'm writing games with Ruby -- it's always nice to have a  
> > single EXE distribution that contains all the game media.)
> > 
> > Thank you for a great library!

---

<div class="post-metadata">

**Author:** ![Gavin\_Sinclair](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Gavin\_Sinclair](https://rubytalk.org/u/Gavin_Sinclair)\
**Post date:** [8 December 2004 15:56 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/7 "2004-12-08T15:56:23Z")

</div>

Try:

&nbsp;&nbsp;require 'rubygems'  
&nbsp;&nbsp;require 'progressbar'

Cheers,  
Gavin

> **···**
>
> On Thursday, December 9, 2004, 2:47:29 AM, Erik wrote:
> 
> > > Will this support all manner of 'require'd files, including  
> > > those loaded by the gems require-hack?
> 
> > [......]
> 
> > ----------------------------------------------------------------
> > 
> > # Doesn't work.
> > 
> > require 'rubygems'  
> > require\_gem 'progressbar'
> > 
> > ----------------------------------------------------------------
> > 
> > # Does work.
> > 
> > require 'rubygems'  
> > begin  
> > &nbsp;&nbsp;&nbsp;require\_gem 'progressbar'  
> > rescue Gem::LoadError  
> > &nbsp;&nbsp;&nbsp;require 'progressbar'  
> > end
> > 
> > ----------------------------------------------------------------

---

<div class="post-metadata">

**Author:** ![Jim\_Weirich1](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Jim\_Weirich1](https://rubytalk.org/u/Jim_Weirich1)\
**Post date:** [8 December 2004 17:42 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/8 "2004-12-08T17:42:41Z")

</div>

Erik Veenstra said:

> I did a test (on Linux) with the progressbar example. Yes,  
> RubyScript2Exe detects progressbar.rb [1] and yes, it is  
> included in the executable [2]. But when the executable is run,  
> require\_gem only searches for progressbar.rb in its own dirs,  
> not in the regular places. Resulting in an Gem::LoadError.

require\_gem does not search for progressbar.rb. It searches for the  
progressbar \*gem\* (progressbar.rb gets required as a side effect if the  
gem specifies an autorequire file). Since you are not replicating the  
gems metadata structure in your packaged app, its not surprizing that it  
is not found.

There are a couple of ways of attacking this. You /could/ replicate the  
gem metadata (not really recommended). Perhaps supplying a custom  
require\_gem that works in your packaged app. I think the only thing the  
custom require\_gem would need to do is do a require on that gems  
autorequire file (if any).

Contact me (or another gem developer) if you need help pursuing this. We  
would be glad to help.

> **···**
>
> --  
> -- Jim Weirich jim@weirichhouse.org [http://onestepback.org](http://onestepback.org)  
> -----------------------------------------------------------------  
> "Beware of bugs in the above code; I have only proved it correct,  
> not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [8 December 2004 19:47 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/9 "2004-12-08T19:47:30Z")

</div>

Erik Veenstra wrote:

> > Is a change list available somewhere? I couldn't find one on  
> > the homepage.
> 
> It's there, really... The Download section [1] has a link to  
> both [2] and [3]. I think you are interested in [2].

Thanks, while this is not exactly what I was looking for it is still similar enough to be of help.

> > Also while I'm writing to you, would it be possible to allow  
> > custom .DLLs and resources to be added? I have an application  
> > that uses a C++ extension which loads more .DLLs --  
> > RubyScript2Exe does not automatically include those and I  
> > can't find a way of manually including them that works. (I  
> > can unpack and repackage, but then the .DLLs will still not  
> > get loaded from the temporary directory.)
> 
> There's a link to Tar2RubyScript [4] on the page as well.  
> Tar2RubyScript generates a standalone Ruby script from an  
> existing directory, which contains a complete Ruby application  
> (scripts, DLL's and resources). This standalone Ruby script can  
> be converted to an executable with RubyScript2Exe.

But will the .DLLs really be found when I use Tar2RubyScript? I think I tried this without success.

---

<div class="post-metadata">

**Author:** ![Erik\_Veenstra3](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@Erik\_Veenstra3](https://rubytalk.org/u/Erik_Veenstra3)\
**Post date:** [11 December 2004 14:27 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/10 "2004-12-11T14:27:23Z")

</div>

> Florian Gross wrote: Erik Veenstra wrote:
> 
> \> \> I just want to say that RubyScript2Exe 0.2.0 [1] has been  
> \> \> released. Both Windows and Linux are supported.  
> \>  
> \> Thank you for a great library!
> 
> This sounds cool. Anyone know what it would take to have this  
> for OS X?

You need "FreePascal on the Macintosh" [1] and a machine with  
OS X. Since I'm the only developer of RubyScript2Exe and not  
possessing such a machine, it will probably never happen.  
Unless somebody is able and willing to do the porting... Or  
provides a SSH connection... I don't think it's to hard to do.

> It would be cool to be able to use RubyCocoa or TKRuby or  
> QTRuby and then make it into an executable easily.

The bindings for QT and TK are detected and included in the  
executable. QT and TK themselfs are not detected, because they  
have nothing to do with Ruby. They have to be installed  
manually.

gegroet,  
Erik V.

[1] [Free Pascal - Free Pascal on the Macintosh](http://www.freepascal.org/fpcmac.html)

> **···**
>
> On Fri, 10 Dec 2004 15:19:04 -0800, steven\_todd\_harri wrote:

---

<div class="post-metadata">

**Author:** ![Its\_Me](https://avatars.discourse-cdn.com/v4/letter/i/958977/32.png) [@Its\_Me](https://rubytalk.org/u/Its_Me)\
**Post date:** [8 December 2004 16:22 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/11 "2004-12-08T16:22:30Z")

</div>

"Gavin Sinclair" \<gsinclair@soyabean.com.au\> wrote in message

> Try:
> 
> &nbsp;&nbsp;require 'rubygems'  
> &nbsp;&nbsp;require 'progressbar'

Will this allow nested (gem and non-gem) requires within 'progressbar' to  
work?

Is the "ruby -r ubygems myfile.rb" and then just plain "require progressbar"  
no longer recommended? Or the environment variable GEM\_PATH (on WinXP) ?

I am trying to settle on one standard way to use my gems transparently i.e.  
without something like 'require\_gem' (or was that 'gem\_require'?). While  
GEM\_PATH seems to work, it appears to cause problems with other apps or libs  
that assume Rubys standard directory layout.

Advice?

---

<div class="post-metadata">

**Author:** ![Erik\_Veenstra3](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@Erik\_Veenstra3](https://rubytalk.org/u/Erik_Veenstra3)\
**Post date:** [8 December 2004 17:37 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/12 "2004-12-08T17:37:35Z")

</div>

> \> \> Will this support all manner of 'require'd files,  
> \> \> including those loaded by the gems require-hack?  
> \>  
> \> [......]
> 
> Try:
> 
> require 'rubygems'
> 
> require 'progressbar'

$ grep \* -wie def | grep -wie require  
loadpath\_manager.rb: def require(file)

Looks like RubyGems does an overwrite of Kernel.require:

module Kernel  
&nbsp;&nbsp;&nbsp;alias require\_\_ require  
&nbsp;&nbsp;&nbsp;def require(file)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gem::LoadPathManager.search\_loadpath(file) || Gem::LoadPathManager.search\_gempath(file)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require\_\_(file)  
&nbsp;&nbsp;&nbsp;end  
end

That will do the trick in our application. But what happens  
when a library does a require\_gem? Time for the next test. I  
don't know Rails, but I think it has some dependencies. Just  
giving it a shot...

Test 1:

$ cat test1.rb  
require "rubygems"  
require\_gem "rails"

$ ruby test1.rb

Looks good. It's useless, but the dependencies are fullfilled.

Test 2:

$ cat test2.rb  
require "rubygems"  
require "rails"

$ ruby test2.rb  
/usr/local/lib/ruby/site\_ruby/1.8/rubygems/loadpath\_manager.rb:5:in `require\_\_': No such file to load -- rails (LoadError)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/rubygems/loadpath\_manager.rb:5:in `require'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from test2.rb:2

Oops! I think it hasn't anything to do with dependencies. The  
trick doesn't work.

Any RubyGem hacker, out there?

gegroet,  
Erik V.

---

<div class="post-metadata">

**Author:** ![Its\_Me](https://avatars.discourse-cdn.com/v4/letter/i/958977/32.png) [@Its\_Me](https://rubytalk.org/u/Its_Me)\
**Post date:** [8 December 2004 19:22 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/13 "2004-12-08T19:22:30Z")

</div>

"Jim Weirich" \<jim@weirichhouse.org\> wrote in message

> Contact me (or another gem developer) if you need help pursuing this. We  
> would be glad to help.

Do you think tt may be good to have a gem-recommended way of dealing with  
this more broadly? With gems gaining wider use this could be useful for any  
app (rubscript, an IDE, etc.) that needs to know about ruby's directory  
structure, and hence about gems.

---

<div class="post-metadata">

**Author:** ![Erik\_Veenstra3](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@Erik\_Veenstra3](https://rubytalk.org/u/Erik_Veenstra3)\
**Post date:** [8 December 2004 23:17 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/14 "2004-12-08T23:17:29Z")

</div>

> \> \> Also while I'm writing to you, would it be possible to  
> \> \> allow custom .DLLs and resources to be added? I have an  
> \> \> application that uses a C++ extension which loads more  
> \> \> .DLLs -- RubyScript2Exe does not automatically include  
> \> \> those and I can't find a way of manually including them  
> \> \> that works. (I can unpack and repackage, but then the  
> \> \> .DLLs will still not get loaded from the temporary  
> \> \> directory.)  
> \>  
> \> There's a link to Tar2RubyScript [4] on the page as well.  
> \> Tar2RubyScript generates a standalone Ruby script from an  
> \> existing directory, which contains a complete Ruby  
> \> application (scripts, DLL's and resources). This standalone  
> \> Ruby script can be converted to an executable with  
> \> RubyScript2Exe.
> 
> But will the .DLLs really be found when I use Tar2RubyScript?  
> I think I tried this without success.

I did it once. It was something like this:

api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")

Newlocation the is path to "the internals of the package". (Of  
course, it's a temp dir...)

But that only works when you directly access the DLL.  
Otherwise, when you access the DLL indirectly, you have to  
change the environment before starting the child process. Could  
be done with:

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" + ENV["PATH"]  
system("command")

You might have to combine them:

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" + ENV["PATH"]  
api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")

Not tested. Just an idea.

gegroet,  
Erik V.

---

<div class="post-metadata">

**Author:** ![Erik\_Veenstra3](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@Erik\_Veenstra3](https://rubytalk.org/u/Erik_Veenstra3)\
**Post date:** [10 December 2004 22:47 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/15 "2004-12-10T22:47:25Z")

</div>

> \> I did a test (on Linux) with the progressbar example. Yes,  
> \> RubyScript2Exe detects progressbar.rb [1] and yes, it is  
> \> included in the executable [2]. But when the executable is  
> \> run, require\_gem only searches for progressbar.rb in its  
> \> own dirs, not in the regular places. Resulting in an  
> \> Gem::LoadError.
> 
> There are a couple of ways of attacking this. You /could/  
> replicate the gem metadata (not really recommended). Perhaps  
> supplying a custom require\_gem that works in your packaged  
> app. I think the only thing the custom require\_gem would need  
> to do is do a require on that gems autorequire file (if any).

RubyScript2Exe executes the application, in order to trace it,  
with (simplified):

$ ruby -r require2lib app.rb

This require2lib sets an at\_exit block. In this block, all  
required and loaded files are copied to ./lib . This ./lib is  
packed into the executable and recreated on the destination  
machine just before doing something like:

$ ruby -I ./lib app.rb

That's part of the job RubyScript2Exe does to satisfy the  
requirements (besides ruby.exe and ruby.dll and a bunch of  
recursively determined dll's en so's).

This copying works for files required via require\_gem as well,  
because the old require is still done by require\_gem, so they  
show up in $". Checked that. It works. It's just that  
rubygems.rb doesn't work properly on the targeted machine,  
because it expects its own environment, which is not recreated.  
My plan was to overwrite this rubygems.rb which a version of my  
own, only implementing require\_gem. I came up with the code  
below.

Any RubyGems hackers willing to have a look at it? Just  
shoot...

Thanks in advance.

gegroet,  
Erik V.

> **···**
>
> ----------------------------------------------------------------
> 
> at\_exit do
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Copy the required files to ./lib .
> 
> &nbsp;&nbsp;&nbsp;$".each do |req|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...  
> &nbsp;&nbsp;&nbsp;end
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Overwrite rubygems.rb with my own version of require\_gem.
> 
> &nbsp;&nbsp;&nbsp;autorequire = {}
> 
> &nbsp;&nbsp;&nbsp;Gem::Specification.list.each do |gem|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unless gem.autorequire.nil?  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unless $".collect{|s| (s =~ /^#{gem.autorequire}\.\w+$/)}.compact.empty?  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;autorequire[gem.name] = gem.autorequire  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;end
> 
> &nbsp;&nbsp;&nbsp;File.open("./lib/rubygems.rb", "w") do |f|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.puts "module Kernel"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.puts " def require\_gem(file, version=nil)"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.puts " autorequire = %s" % autorequire.inspect  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.puts " file = autorequire[file]"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.puts " require(file) unless file.nil?"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.puts " end"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.puts "end"  
> &nbsp;&nbsp;&nbsp;end  
> end
> 
> ----------------------------------------------------------------
> 
> > Contact me (or another gem developer) if you need help  
> > pursuing this. We would be glad to help.
> 
> (I tried, no response...)

---

<div class="post-metadata">

**Author:** ![Mauricio\_Fernndez](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mauricio\_Fernndez](https://rubytalk.org/u/Mauricio_Fernndez)\
**Post date:** [8 December 2004 16:57 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/16 "2004-12-08T16:57:42Z")

</div>

> "Gavin Sinclair" \<gsinclair@soyabean.com.au\> wrote in message  
> \> Try:  
> \>  
> \> require 'rubygems'  
> \> require 'progressbar'
> 
> Will this allow nested (gem and non-gem) requires within 'progressbar' to  
> work?

require 'foo' will always load the version from RubyGems, if you're  
referring to that. Once you require 'rubygems', it overrides  
Kernel.require and it is no longer possible to load the files in the  
standard library dir, unless you use the GEM\_SKIP env. variable.

> Is the "ruby -r ubygems myfile.rb" and then just plain "require progressbar"  
> no longer recommended? Or the environment variable GEM\_PATH (on WinXP) ?

ruby -rubygems foo is equivalent to doing a require 'rubygems'...

> **···**
>
> On Thu, Dec 09, 2004 at 01:22:30AM +0900, itsme213 wrote:
> 
> --  
> Hassle-free packages for Ruby?  
> RPA is available from [http://www.rubyarchive.org/](http://www.rubyarchive.org/)

---

<div class="post-metadata">

**Author:** ![Jim\_Weirich1](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Jim\_Weirich1](https://rubytalk.org/u/Jim_Weirich1)\
**Post date:** [8 December 2004 18:57 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/17 "2004-12-08T18:57:17Z")

</div>

itsme213 said:

> I am trying to settle on one standard way to use my gems transparently  
> i.e.  
> without something like 'require\_gem' (or was that 'gem\_require'?). While  
> GEM\_PATH seems to work, it appears to cause problems with other apps or  
> libs that assume Rubys standard directory layout.
> 
> Advice?

If you don't care what version you get, just do a normal require. In  
addition, you need to make sure the rubygems library is loaded. You can  
do this by:

\* explicitly requiring 'rubygems' before requiring any file  
&nbsp;&nbsp;that would be in a gem.[1]  
\* explicitly starting ruby with a -rubygems command line option.  
\* Setting the RUBYOPT environment variable to 'rubygems'

If you /do/ care about which the version of a gem you are using, then use  
a require\_gem command with explicit versioning requirements. Again, make  
sure the rubygems library is loaded using one of the above three  
techniques.

Regarding your GEM\_PATH comment, I'm not sure what you are getting at.  
GEM\_PATH is for specifying where multiple gem repositories are locally  
stored. Were you refering to RUBYOPT?

> **···**
>
> --  
> -- Jim Weirich jim@weirichhouse.org [http://onestepback.org](http://onestepback.org)  
> -----------------------------------------------------------------  
> "Beware of bugs in the above code; I have only proved it correct,  
> not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
> 
> [1] If you do choose to explicitly include rubygems, but don't  
> &nbsp;&nbsp;&nbsp;&nbsp;want to depend on rubygems always being available, do this:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require 'rubygems'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rescue LoadError  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

---

<div class="post-metadata">

**Author:** ![Jim\_Weirich1](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Jim\_Weirich1](https://rubytalk.org/u/Jim_Weirich1)\
**Post date:** [8 December 2004 20:12 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/18 "2004-12-08T20:12:51Z")

</div>

itsme213 said:

> Do you think tt may be good to have a gem-recommended way of dealing with  
> this more broadly? With gems gaining wider use this could be useful for  
> any  
> app (rubscript, an IDE, etc.) that needs to know about ruby's directory  
> structure, and hence about gems.

Coincidently, on the rubygems-dev mailing list we just had a discussion on  
the value of identifying an "API" for gems that identifies some kind of  
programatic interface for doing gem related things. These kinds of  
operations certainly fall into that category.

Thanks for the feedback. We certainly want to head in that direction.

> **···**
>
> --  
> -- Jim Weirich jim@weirichhouse.org [http://onestepback.org](http://onestepback.org)  
> -----------------------------------------------------------------  
> "Beware of bugs in the above code; I have only proved it correct,  
> not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

---

<div class="post-metadata">

**Author:** ![Erik\_Veenstra3](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@Erik\_Veenstra3](https://rubytalk.org/u/Erik_Veenstra3)\
**Post date:** [8 December 2004 23:22 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/19 "2004-12-08T23:22:29Z")

</div>

Long lines... Sorry.

> ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" +  
> ENV["PATH"] system("command")

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") +  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";" +  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENV["PATH"]

system("command")

> ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" +  
> ENV["PATH"] api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P  
> P), "V")

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") +  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";" +  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENV["PATH"]

api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [9 December 2004 00:22 UTC](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204/20 "2004-12-09T00:22:29Z")

</div>

Erik Veenstra wrote:

> > > > custom DLLs
> > > 
> > > Tar2RubyScript
> > 
> > But will the .DLLs really be found when I use Tar2RubyScript?  
> > I think I tried this without success.
> 
> I did it once. It was something like this:
> 
> api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")
> 
> [...]
> 
> ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" + ENV["PATH"]  
> system("command")

Not doing either of those though. I'm just require()ing a Ruby library (C++ extension) that is dynamically linked against a few DLLs. One of those is fmod.dll, but there's also msvcp71.dll and msvcr71.dll and a custom one involved. I know that RubyScript2Exe is already able to bundle the DLLs that Ruby uses so an option for adding the specified DLLs in a similar way would be just what I need. I'm not sure if this involves doing a Win32-API call to tell Ruby to also look for DLLs at the location the executable was unpacked to. Does this sound possible?

Thanks a lot for helping out with this.

[Next page](https://rubytalk.org/t/ann-rubyscript2exe-0-2-0/15204.md?page=2)
