On 31 ene, 16:53, Paul Brannan <pbran... / atdesk.com> wrote:
> On Thu, Feb 01, 2007 at 02:20:38AM +0900, Rob Sanheim wrote:
> > Ugh, so I need that at the top of all these scripts?  I thought
> > /usr/bin/env was the 'better' way to go?
>
> This issue has come up before (see [ruby-talk:27508]).  However, Austin
> Ziegler pointed out in [ruby-talk:56340] that the sh/exec solution won't
> work on non-Unix environments.  See also 'perldoc perlrun' for more
> discussion on the issue (ruby takes much of its behavior from perl in
> this case).
>
> Paul

All solutions posted so far are broken in one way or another.

What will work across platforms and OSes is this:

#! /usr/bin/env ruby

And add:

export RUBYOPT="-w $RUBYOPT"

to your environment (.bashrc) or:

setenv RUBYOPT "-w $RUBYOPT"

for cshrc, tcsh (.cshrc, .tcshrc, etc).   For windows, do:

set RUBYOPT="-w %RUBYOPT%"

in a bat file (or in your environment variables for the user or the
machine).
The additional benefit of this is that you will not only get your
little script compiled with warnings on, but every piece of ruby code
you run, too.
Also, if you need performance, you can easily turn off the -w flag,
without having to modify a single file.