6

I did this in test.rb:

def some_method
  p "First definition"
end

def some_method
  p "Second definition"
end

some_method

When I call ruby test.rb, it prints Second definition (expected)

When I call ruby -w test.rb, it prints Second definition (expected) and prints a warning test.rb:5: warning: method redefined; discarding old some_method

Is there a way to enable those warnings in Rails? (and print the warning to the console/log file)

Why I would like to enable warnings: For example if I inadvertently re-define a method in a controller, then I would be aware of the problem by looking at the warning printed to the console/log file. See here for an example.

Community
  • 1
  • 1
Zabba
  • 64,285
  • 47
  • 179
  • 207

1 Answers1

5

Put this somewhere in your initialisation code (such as config/application.rb):

$VERBOSE = true

You'll probably also get some warnings from Rails itself though.

molf
  • 73,644
  • 13
  • 135
  • 118
  • 1
    This helps as a starter, thanks. I will look for some way (if possible!) to turn off the warnings for the Rails/3rd party code! I've written a log highlighter, so maybe I will highlight in the console, in red, the source code directory of *my* app, so I can pay attention to it whild ignoring the the myriads of warnings from Rails. – Zabba May 26 '11 at 07:57
  • @Zabba did you end up finding a way to do this? – patrickdavey Feb 26 '16 at 14:48
  • @patrick-davey, no. But today I found this blog http://mislav.net/2011/06/ruby-verbose-mode/ (ironically written 1 month after I had this problem; why didn't I find it back then?! heh.) – Zabba Mar 12 '16 at 05:35