maasha maasha - 1 year ago 155
Ruby Question

How to run Ruby script with env and warnings enabled?

I prefere to invoke Ruby scripts with a hash bang line using

#!/bin/env ruby
which allows me to use a local Ruby installation without conflicting with the systems Ruby installation. But how can I enable warnings on Linux systems? My test script:

#!/usr/bin/env ruby -w


On Mac I get:

maasha@mel:~$ ./test.rb
./test.rb:3: warning: possibly useless use of a constant in void context
./test.rb:3:in `<main>': uninitialized constant FOO (NameError)

On Linux I get:

maasha@orsted:~$ ./test.rb
/usr/bin/env: ruby -w: No such file or directory

Answer Source

#!/usr/bin/env RUBYOPT=-w ruby

As suggested in this answer, this answer, and other places

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download