rubycomputer-scienceocra

Ruby : my program creates .exe but can't without ocra installed in another computer


Ocra is a ruby gem "transforming" ruby files source code to a .exe file, so any user without ruby installed can launch the program with that generated file.

I'm creating a game editor, so I need a way to create an executable when the user wants to.

Well, here is my question, how can I use ocra command without telling the user to install that gem ? A kind of require (require 'ocra' is not working), or another way to create an executable.


Solution

  • Thanks to Raffael's answer, it's working like that :

    Forget the idea of using exec("ocra game.rbw") into the program. With my computer with ocra installed, I created a basic game.exe with game.rbw that will be interpreted differently thanks to eval. The idea is that instead of creating a new .exe for each different project, we will set it thanks to source code interpretation.

    If you had something like that into game.rbw :

    Dir.entries("SourceCode").each do |code|
        require_relative "SourceCode/" + code if code.include?(".rb")
    end
    

    Replace it by :

    Dir.entries("SourceCode").each do |code|
        eval(File.open("SourceCode/" + code, "r:UTF-8").readlines.join("\n")) if code.include?(".rb") 
    end
    

    If you set a part of your source code, next time launching your game.exe would be interpreted differently.