For a project (which consists of several independent Ruby programs), I
wanted to provide an easy way to enable warnings in Ruby, but not
necessarily force it to be used in every single application. What I
basically ended up with (I’m leaving out irrelevant details) was a file
warnings.rb, which had the following:
BEGIN { $VERBOSE = true }
To enable warnings in an application, one can either
require 'warnings'
or run the application using
ruby -r warnings .....
(One might argue that the latter could also be achieved by running the
program using ruby -w, but warnings.rb also provides other stuff related
to this topic).
This solution works so far to our satisfaction. Now someone pointed out
to me that in this case, the BEGIN block is really unnecessary. When I
gave it a second thought, the only case I could come of would be the
following situation: Someone else runs code in a BEGIN block which, when
executed, would cause warnings. This is a pretty exotic situation, so I
think I can remove the BEGIN block without doing any harm.
Am I right, or did I miss something?