How to run a ruby script within bundler context?

后端 未结 3 1699
深忆病人
深忆病人 2021-02-01 12:04

I have a Ruby script called foo.rb, and I want to run it within the context of the bundler environment. How?

bundle exec foo.rb doesn\'t work, because exec

3条回答
  •  独厮守ぢ
    2021-02-01 12:45

    You can just make it a script - add

    #!/usr/bin/env ruby
    

    to the start of the file, and make it executable. Then bundle exec foo.rb will work as expected.

    (This is on unix or OSX - not sure about Windows)

    See http://bundler.io/v1.15/man/bundle-exec.1.html#Loading

    Also see https://coderwall.com/p/kfyzcw/execute-ruby-scripts-directly-without-bundler-exec for how to run ruby scripts with bundled dependencies, without needing bundle exec

提交回复
热议问题