Problem with using Ocra

Something what I expected and didn’t wanted to happen; HAPPENED!

If you use ocra gem you definitely understand what I’m saying but if you
don’t I’ll explain.

Ocra is a gem that is used to compile a ruby script into executables
(.exe)

The very bad thing is that whenever you try to ocra your script into an
exe it checks dependencies i.e runs the code and until it comes to the
last line of the code and ends it won’t stop, literally, you need to go
to the last line of the code to successfully turn it into an exe file.

The problem is I’m using a loop in my code and I don’t see ocra getting
to the end of my code.

loop = 1
while loop < 100
#do this

loop = loop + 1
end

Now I wouldn’t want to press enter a 100 times so my code can turn into
exe so is there any possible way to avoid this?

On Sat, Mar 1, 2014 at 11:29 AM, cynic limbu [email protected]
wrote:

last line of the code and ends it won’t stop, literally, you need to go
end

Now I wouldn’t want to press enter a 100 times so my code can turn into
exe so is there any possible way to avoid this?


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

You might be having a conflict with Kernel#loop method…

You might be having a conflict with Kernel#loop method…

Please try to explain it as simply with possible.

I’m not a professional programmer.

Short answer: change your variable named “loop” to something else,
such as “my_loop”.

Longer answer, but still very short given the nature of it:

There is a ruby construct:

loop do

your loop code here

end

loop is a method from the Kernel module.

Read about it here:
http://ruby-doc.org/core-2.0.0/Kernel.html#method-i-loop

loop is a method from the Kernel module.

Logically speaking, whenever you ocra your script it runs the script
until ocra gets to the end of it, I also tried your suggestion, it
didn’t solved my problem, I’m still stuck.

Thank you for trying.

Put this at the start of your script:

exit if defined?(Ocra)

If there are any gems or non-standard libraries which need to be
explicitly used in order for Ocra to pick them up, you just extend that
section of code to use them before calling “exit”, which quits your
script and hands control back to Ocra.
Something like this would work to pick up the files for Watir:

if defined?(Ocra)
Watir::Browser.new.close
exit
end

Just remember that exe files are flagged as potentially dangerous, so
you have to consider the security implications.

Joel P. wrote in post #1138558:

If there are any gems or non-standard libraries which need to be
explicitly used in order for Ocra to pick them up, you just extend that
section of code to use them before calling “exit”, which quits your
script and hands control back to Ocra.
Something like this would work to pick up the files for Watir:

I’m not sure if I totally understood what you meant by that.

I use multiple gems for my programs

do you mean something like this?

if defined?(Ocra)
require ‘example’
require ‘otherexample’
require ‘moreexample’
end

exit if defined?(Ocra)

Hello, it worked! Thank you very much, The last question I’d like to ask
for is are there any precautions to take by using the code above?

And finally, Can I just upload the given .exe online and can someone run
it without any problem?

cynic limbu wrote in post #1138584:

Joel P. wrote in post #1138558:

If there are any gems or non-standard libraries which need to be
explicitly used in order for Ocra to pick them up, you just extend that
section of code to use them before calling “exit”, which quits your
script and hands control back to Ocra.

I’m not sure if I totally understood what you meant by that.

I use multiple gems for my program

do you mean something like this?

if defined?(Ocra)
require ‘example’
require ‘otherexample’
require ‘moreexample’
exit
end

Ocra picks up most of the gems and source files anyway, but sometimes
you might have a section of a gem which isn’t required until you use it
within the code.

If it works fine with the first example then you don’t need to worry
about it.
If your exe fails because it’s missing components, then you might need
the second example.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs