Forum: Ruby To BEGIN or not to BEGIN

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?
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.