5

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 
3
  • I have noted the possibility to set export RUBYOPT=-w, but I would like to avoid that if possible. Commented Feb 21, 2013 at 10:58
  • There is a thread on the topic on ruby forum: ruby-forum.com/topic/96121 Commented Feb 21, 2013 at 11:11
  • More on env and multiple arguments here: stackoverflow.com/questions/4303128/… Commented Feb 21, 2013 at 11:13

2 Answers 2

3

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

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

Sign up to request clarification or add additional context in comments.

4 Comments

Oh, and now you tell me! After 3 years! ;o)
Sorry, I just hadn't see your question before - or found an answer, I just went looking again and this time found both
... apparently that doesn't work on all systems, so here's another method: make your first non-comment line $VERBOSE = true
You better add that as a separate answer.
2

My first answer doesn't work on all systems, so here's another method: make your first non-comment line

$VERBOSE = true 

which is What the -w switch does. From http://linux.die.net/man/1/ruby:

-v'

--verbose' Enables verbose mode. Ruby will print its version at the beginning, and set the variable $VERBOSE to true. Some methods print extra messages if this variable is true. If this switch is given, and no other switches are present, Ruby quits after printing its version.

-w' Enables verbose mode without printing version message at the beginning. It sets the $VERBOSE variable to true.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.