Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Ruby script with env and warnings enabled?

Tags:

ruby

warnings

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

FOO

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
like image 340
maasha Avatar asked Feb 21 '13 10:02

maasha


People also ask

How do you use environment variables in Ruby?

Passing Environment Variables to Ruby To pass environment variables to Ruby, simply set that environment variable in the shell. This varies slightly between operating systems, but the concepts remain the same. To set an environment variable on the Windows command prompt, use the set command.

Where are Ruby environment variables stored?

You store separate environment variables in config/development. rb , config/testing. rb and config/production. rb respectively.

What is ENV fetch?

The fetch() method of the ENV class fetches or finds an environment variable. It takes the environment variable's name and returns the value of this environment variable.


1 Answers

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

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

like image 200
ShadSterling Avatar answered Sep 23 '22 19:09

ShadSterling