Running another ruby script from a ruby script

后端 未结 7 993
终归单人心
终归单人心 2020-12-01 04:48

In ruby, is it possible to specify to call another ruby script using the same ruby interpreter as the original script is being run by?

For example, if a.rb runs b.rb

7条回答
  •  既然无缘
    2020-12-01 05:02

    If you just want to run a script in the context of an existing process, you can also do this

    eval File.read("/path/to/your/script.rb")
    

    Not sure what your use case is but this could be useful for example if you have a Rails console open and you want to execute some code in a scratch file, but don't want to have to keep copying the entire block of code into your console.

提交回复
热议问题