Is there a way to capture the warnings, something like rescue for exceptions? I do not want to simply disable the warnings (by doing $VERBOSE = nil) but want to capture the content of the warning messages during run time.
3 Answers
This is kinda ugly because you will be writing to files and you might not have permission to write to them, and it will hide ALL output to $stderr, not just the warnings, but it works:
$stderr.reopen("errors.txt") MyConst = 4 MyConst = 5 # generates a warning on the standard error output $stderr.reopen("errors2.txt") puts "The following errors happened:" puts File.read("errors.txt") 1 Comment
sawa
Can it be redirected to some Ruby internal IO rather than an external file?