Forum: Ruby To BEGIN or not to BEGIN

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2017-04-10 14:58
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?
This topic is locked and can not be replied to.