Running another ruby script from a ruby script

后端 未结 7 996
终归单人心
终归单人心 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 04:54

    This is what I have used

    /myapp/script/main_script.rb


    load rails env, only if you need to

    ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development'
    require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
    

    run other slave scripts from within main_script.rb

    require File.expand_path(File.dirname(__FILE__) + "/../script/populate_wh_grape_varieties_table.rb")
    

提交回复
热议问题