Forum: Ruby Hiding warnings

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ddbd8bc32e3a87163b4658b2785d2082?d=identicon&s=25 Mark Somerville (Guest)
on 2006-02-10 11:13
(Received via mailing list)
I have a couple of sections of code that I don't want any warnings
displayed
for. I'd still like the warnings for the rest of the application.

Can I turn warnings on and off programatically?

Mark
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-02-10 11:27
(Received via mailing list)
On Feb 10, 2006, at 11:13, Mark Somerville wrote:

> I have a couple of sections of code that I don't want any warnings
> displayed
> for. I'd still like the warnings for the rest of the application.
>
> Can I turn warnings on and off programatically?

Yes, the idiom is $VERBOSE = nil.

-- fxn

% irb
irb(main):001:0> a = []
=> []
irb(main):002:0> a.push (0)
(irb):2: warning: don't put space before argument parentheses
=> [0]
irb(main):003:0> current_W = $VERBOSE
=> false
irb(main):004:0> $VERBOSE = nil
=> nil
irb(main):005:0> a.push (0)
=> [0, 0]
irb(main):006:0> $VERBOSE = current_W
=> false
irb(main):007:0> a.push (0)
(irb):7: warning: don't put space before argument parentheses
=> [0, 0, 0]
Ddbd8bc32e3a87163b4658b2785d2082?d=identicon&s=25 Mark Somerville (Guest)
on 2006-02-10 12:11
(Received via mailing list)
Spot on, thanks Xavier.

Mark
This topic is locked and can not be replied to.