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
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.
You store separate environment variables in config/development. rb , config/testing. rb and config/production. rb respectively.
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.
#!/usr/bin/env RUBYOPT=-w ruby
As suggested in this answer, this answer, and other places
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With