execute ruby scripts directly without bundler exec
You can execute ruby scripts directly in a directory with a bundler Gemfile without having to invoke them with the bundler exec command by requiring budler/setup in your script.
In this example assume that the Gemfile includes active_support such as in a Rails app. example.rb:
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'active_support/all'
# overkill example, blank? is defined in active support
puts " nil is blank? #{nil.blank?}"
puts " '' is blank? #{''.blank?}"
puts "'foo' is blank? #{'foo'.blank?}"
Ensure the script is executable and then call it directly.
% chmod +x example.rb
% ./example.rb
nil is blank? true
'' is blank? true
'foo' is blank? false
Written by Mike Mondragon
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#