# Problem with using Ocra

**URL:** <https://www.ruby-forum.com/t/problem-with-using-ocra/239501>\
**Category:** Ruby\
**Created:** [March 1, 2014, 6:29pm UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501 "2014-03-01T18:29:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [March 1, 2014, 6:29pm UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/1 "2014-03-01T18:29:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cyniclimbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@cyniclimbu](https://www.ruby-forum.com/u/cyniclimbu)\
**Post date:** [March 1, 2014, 6:31pm UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/2 "2014-03-01T18:31:48Z")

</div>

On Sat, Mar 1, 2014 at 11:29 AM, cynic limbu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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/](http://www.ruby-forum.com/).

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

---

<div class="post-metadata">

**Author:** ![cyniclimbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@cyniclimbu](https://www.ruby-forum.com/u/cyniclimbu)\
**Post date:** [March 1, 2014, 6:54pm UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/3 "2014-03-01T18:54:27Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![cyniclimbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@cyniclimbu](https://www.ruby-forum.com/u/cyniclimbu)\
**Post date:** [March 1, 2014, 7:00pm UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/4 "2014-03-01T19:00:03Z")

</div>

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:

> **[Module: Kernel (Ruby 2.0.0)](http://ruby-doc.org/core-2.0.0/Kernel.html#method-i-loop)**
>
> Repeatedly executes the block. | Module : Kernel - Ruby 2.0.0

---

<div class="post-metadata">

**Author:** ![cyniclimbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@cyniclimbu](https://www.ruby-forum.com/u/cyniclimbu)\
**Post date:** [March 1, 2014, 7:21pm UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/5 "2014-03-01T19:21:08Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![cyniclimbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@cyniclimbu](https://www.ruby-forum.com/u/cyniclimbu)\
**Post date:** [March 1, 2014, 8:41pm UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/6 "2014-03-01T20:41:03Z")

</div>

Put this at the start of your script:

exit if defined?(Ocra)

---

<div class="post-metadata">

**Author:** ![cyniclimbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@cyniclimbu](https://www.ruby-forum.com/u/cyniclimbu)\
**Post date:** [March 2, 2014, 7:32pm UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/7 "2014-03-02T19:32:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cyniclimbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@cyniclimbu](https://www.ruby-forum.com/u/cyniclimbu)\
**Post date:** [March 3, 2014, 7:16am UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/8 "2014-03-03T07:16:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cyniclimbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@cyniclimbu](https://www.ruby-forum.com/u/cyniclimbu)\
**Post date:** [March 2, 2014, 2:14pm UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/9 "2014-03-02T14:14:20Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![cyniclimbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@cyniclimbu](https://www.ruby-forum.com/u/cyniclimbu)\
**Post date:** [March 3, 2014, 7:17am UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/10 "2014-03-03T07:17:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cyniclimbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@cyniclimbu](https://www.ruby-forum.com/u/cyniclimbu)\
**Post date:** [March 3, 2014, 8:39pm UTC](https://www.ruby-forum.com/t/problem-with-using-ocra/239501/11 "2014-03-03T20:39:44Z")

</div>

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.
