Forum: Ruby-core [ruby-trunk - Bug #7899][Open] Add feature similar to: perl use warnings

Posted by Markus H. (markus_h)
on 2013-02-21 12:23
(Received via mailing list)
Issue #7899 has been reported by shevegen (markus heiler).

----------------------------------------
Bug #7899: Add feature similar to: perl use warnings
https://bugs.ruby-lang.org/issues/7899

Author: shevegen (markus heiler)
Status: Open
Priority: Low
Assignee:
Category:
Target version:
ruby -v: 1.9.3p385


<maasha> shevy: It would be nice ruby had a way to enable warnings 
within the code - like perl's `use warnings;`


Hi,

Background to this is that maasha had problems with shebang, 
/usr/bin/env and "ruby -w" as part of the shebangs.

He was able to workaround this by setting RUBYOPT:

<maasha> shevy: I think the conclusion is that one needs to set: export 
RUBYOPT=-w

A bit background is here:

http://stackoverflow.com/questions/4303128/how-to-...

Now one suggestion is to set $VERBOSE to 2 or true. But I am not sure 
whether this is the
best or most elegant solution.

Could there be a way to enable and disable warnings globally within a 
.rb script?

Kernel.enable_warnings
Kernel.disable_warnings

Something like that?

Then users could specifically choose to ignore certain warnings, if they 
want to (like during development when they dont care about all warnings 
in every .rb file of a project).
Posted by drbrain (Eric Hodel) (Guest)
on 2013-02-21 22:09
(Received via mailing list)
Issue #7899 has been updated by drbrain (Eric Hodel).

Category set to core
Status changed from Open to Closed
Priority changed from Low to Normal

Use $VERBOSE or $-w:

  $ cat test.rb
  "".gsub /x/, ''
  $ ruby19 -wv test.rb
  ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.1]
  test.rb:1: warning: ambiguous first argument; put parentheses or even 
spaces

  $ cat test.rb
  $VERBOSE = true
  "".gsub /x/, ''
  $ ruby19 -v test.rb
  ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.1]
  test.rb:2: warning: ambiguous first argument; put parentheses or even 
spaces

  $ cat test.rb
  $-w = true
  "".gsub /x/, ''
  $ ruby19 -v test.rb
  ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.1]
  test.rb:2: warning: ambiguous first argument; put parentheses or even 
spaces

I will update documentation in doc/globals.rdoc to better describe the 
behavior of these two globals.
----------------------------------------
Bug #7899: Add feature similar to: perl use warnings
https://bugs.ruby-lang.org/issues/7899#change-36718

Author: shevegen (markus heiler)
Status: Closed
Priority: Normal
Assignee:
Category: core
Target version:
ruby -v: 1.9.3p385


<maasha> shevy: It would be nice ruby had a way to enable warnings 
within the code - like perl's `use warnings;`


Hi,

Background to this is that maasha had problems with shebang, 
/usr/bin/env and "ruby -w" as part of the shebangs.

He was able to workaround this by setting RUBYOPT:

<maasha> shevy: I think the conclusion is that one needs to set: export 
RUBYOPT=-w

A bit background is here:

http://stackoverflow.com/questions/4303128/how-to-...

Now one suggestion is to set $VERBOSE to 2 or true. But I am not sure 
whether this is the
best or most elegant solution.

Could there be a way to enable and disable warnings globally within a 
.rb script?

Kernel.enable_warnings
Kernel.disable_warnings

Something like that?

Then users could specifically choose to ignore certain warnings, if they 
want to (like during development when they dont care about all warnings 
in every .rb file of a project).
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.