RubyScript2Exe fix for bug in line 621?

I am new to Ruby, but not to programming. I have spent several hours
researching how to get RubyScript2Exe to work with Ruby version
1.8.6-p287.

RubyScript2Exe is no longer maintained, however. Because of this, there
is a bug in line 621 that, with version 1.8.6-p287 of Ruby, produces
this error, (without the quotes):

“rubyscript2exe.rb:621:in ‘replace’: can’t modify frozen string
(TypeError)”

In my research, I came across this:

http://www.ruby-forum.com/topic/183234

There, it is suggested that line 621, which is:

$0.replace(File.expand_path("./init.rb"))

…should be replaced by:

$0 = File.expand_path("./init.rb")

Maybe this works for some people, I don’t know. I do know that it
didn’t work for me.

Later in my research, I found this:

http://rha7dotcom.blogspot.com/2008/09/rubyscript2exerb-and-623-cant-modify.html

First, a quick note to avoid confusion. The blogger mistakingly said
the bug is on line 623. This is probably because he added a few lines
somewhere earlier on in the program.

Anyway, it is suggested that the buggy line (which is line 621) should
be replaced by:

$_0 = File.expand_path("./init.rb")
alias $__0 $0
alias $0 $_0

It seems that this fix may have helped some people. However, it did not
work when I tried it. There was no error, but it didn’t make the exe.

The OS I tried it on was Vista. The program I was trying to compile was
a one line Hello World program with the filename “Hello_World” (without
the quotes).

By the way, technically, it seems that the bug is not in RubyScript2Exe
but in the program that compresses it. However, they are both located
in the same Ruby file.

If you need to ask any more information to diagnose the problem, go
ahead.

Could anyone please make a fix that works for me? Such a fix would
likely benefit many people. If no one can, could someone tell me if
there are any other programs that can make an exe from a Ruby file?

Thank you VERY much!

On Jun 30, 5:56 pm, __ __ removed_email_address@domain.invalid wrote:

$0 = File.expand_path("./init.rb")
somewhere earlier on in the program.

Could anyone please make a fix that works for me? Such a fix would
likely benefit many people. If no one can, could someone tell me if
there are any other programs that can make an exe from a Ruby file?

Thank you VERY much!

Posted viahttp://www.ruby-forum.com/.

Since you are working with Windows I then look into ‘ocra’ this is a
very good alternate to rubyscript2exe. It works with the latest ruby
interpretrs.

Hope this helps

On Jul 1, 11:15 am, __ __ removed_email_address@domain.invalid wrote:

that I should have been more open to alternatives from the start.

Lars C. wrote ocra because rubyscript2exe does not work with
the latest ruby interpreters.

Out of curiosity, though, are there alternatives to RubyScript2Exe for
non-Windows users?

‘crate’ is supposed to be cross-platform but from what I understand it
has its problem with Windows. It is a more complex program.

Oh, and what good GUI and graphics gems are compatible with OCRA? I
like Shoes, but it’s not a gem, so I doubt it’s compatible. Or at least
if it is compatible, I doubt it would be very straightforward to get
them to work together.

I am not sure what you mean by "compatible with OCRA. " Neither ocra
nor crate are development programs. The idea behind both of these gems
is for you to write, test and debug your program. You then call on
ocra or crate to package your program into an ‘exe’ that can run your
program on a computer that does not have ruby installed. Note that I
said package as opposed to compile. Both of these gems
gather the ruby interpreter, the supporting resources your program
requires, and your source code. Whether you use a console or an ide to
develop your program is up to you. Your program can either be a
graphical program or a console program.

I have not tried to package a program develop with Shoes … ocra may
not be able to package since Shoes has its own ruby interpreter.

Regards

bbiker

let me know how made out with ocra.

Bernard K. wrote:

Since you are working with Windows I then look into ‘ocra’ this is a
very good alternate to rubyscript2exe. It works with the latest ruby
interpretrs.

Hope this helps

Thank you for the excellent response! I have never heard of OCRA
before, but it looks really good, and I’ll give it a try! I see now
that I should have been more open to alternatives from the start.

Out of curiosity, though, are there alternatives to RubyScript2Exe for
non-Windows users?

Oh, and what good GUI and graphics gems are compatible with OCRA? I
like Shoes, but it’s not a gem, so I doubt it’s compatible. Or at least
if it is compatible, I doubt it would be very straightforward to get
them to work together.

Thanks!

I am not sure what you mean by "compatible with OCRA. "

Specifically, I meant the gem is capable of being compiled by OCRA.
From your response, it sounds like all gems are compatible. That’s good
to know.

I have not tried to package a program develop with Shoes … ocra may
not be able to package since Shoes has its own ruby interpreter.

I figured as much. That’s okay; there are bound to be some good GUI and
graphics gems out there, although I can’t think of any at the moment.
What do you people recommend?

let me know how made out with ocra.

I tried OCRA, and it works great so far! I haven’t had any problems
with it. Granted, I did test it on only a Hello World script, so I
haven’t tried it with gems yet. However, I don’t doubt it works with
gems.

Please, let me emphasize that ocra, rubyscript2exe, and crate do not
“compile” your program into an executable binary code.

It seems we have a misunderstanding of semantics. I apologize, and I
take the blame. I believe I can clear this up rather quickly.

I have understood that these programs do not technically compile since
before your explanations. I used the word compile only because I saw
the author of RubyScript2Exe call his program a compiler. At the time,
I didn’t know a better term for it. I apologize for not making this
clear before. From your helpful response, it seems the best term is
package. I would not at all mind saying package instead of compile to
describe this.

I understand all your detailed explanations. Thank you.

I have not programmed any GUI programs. There have been several
threads on mailing lists that discuss the various gui available.
Ask 10 programmers and you’ll get 20 opinions. It would be worthwhile
for you to use google.

In my previous attempts at using Google, I didn’t find any I wanted to
try. However, I took your excellent advice of searching for threads
that discuss it, and found Gosu. Thanks!

On Jul 3, 5:51 pm, __ __ removed_email_address@domain.invalid wrote:

I am not sure what you mean by "compatible with OCRA. "

Specifically, I meant the gem is capable of being compiled by OCRA.
From your response, it sounds like all gems are compatible. That’s good
to know.

Please, let me emphasize that ocra, rubyscript2exe, and crate do not
“compile” your program into an executable binary code.
All they do is package the ruby interpreter, the required resources
(gems and any other needed libraries), and your source files
into a bundle with an .exe’ extension. At runtime, all the files are
unpacked into a temporary directory and run your program. Effectively
a ruby installation is placed on the host computer which stays
resident until your program terminates. Crate accomplishes this
differently
but for all practical purposes it is essentially the same idea.

When ocra invokes your program, the program only needs to run until
all the ‘requires’ have been executed. At that point, your program
could be terminated and ocra would have enough information to package
your program.

The "magical’ statement is:
exit if Objective.const_defined?(:Ocra)

You can verify by placing this statement before your program prints
“Hello World”. Your “executable” program will run to completion.

For example I have a program which normally requires 1/2 hour runtime.

Here is the beginning of the top level source file

gems that the program needs

require ‘rubygems’
require ‘windows/api’
include Windows

source files that make up the programs

require ‘dealer’
require ‘df’
require ‘analysis’
require ‘report’

exit if Object.const_defined?(:Ocra)

When invoked via ocra, the program terminates in a blink of an eye
and ocra begins its packaging at that point.

The console output lists all the resources that makeup the package.

A point you should be aware. If your program interfaces with external
programs, these programs are not part of the package.

In my program, dealer.rb executes an external program via a dos
console and df.rb controls an external program via its dll.
This means that the .exe must be run in the directory that
these external programs exist.

I figured as much. That’s okay; there are bound to be some good GUI and
graphics gems out there, although I can’t think of any at the moment.

What do you people recommend?
I have not programmed any GUI programs. There have been several
threads on mailing lists that discuss the various gui available.
Ask 10 programmers and you’ll get 20 opinions. It would be worthwhile
for you to use google.

I tried OCRA, and it works great so far! I haven’t had any problems
with it. Granted, I did test it on only a Hello World script, so I
haven’t tried it with gems yet. However, I don’t doubt it works with gems.
A long journey begins but with one step.

In my opinion, if you want to know how a horse feels, ask the horse
and not the jockey.
A good resource for programming ruby in windows is:
http://rubyonwindows.blogspot.com/

http://rubyforge.org/forum/?group_id=8185 is the forum url for ocra.
Lars C. the author of ocra
has shown to be responsive to question and uncovered bugs.

Please do not take the above as a put off. I am glad to answer your
questions. But I am just someone that
bet on the horse and came out a winner.

I have not mentioned that rubyscript2exe has problems with ruby-1.8.6
and later. It appears that for one reason or another it is no longer
supported. It is a shame, since the author (Erik V.) has
contributed very good gems to the Ruby community.

Regards
Bernard K.
removed_email_address@domain.invalid