0
我驚訝地得知,警告默認情況下,在耙顯然禁用:爲什麼警告在默認情況下會在rake中被禁用?
def broken_code
path = '/tmp/foo'
# create empty file
File.open(path, 'w')
# when warnings are enabled you get a warning here- File#new does not take a block
File.new(path) do |f|
puts "never get here..."
end
end
task :no_warnings do |t|
broken_code
end
task :warnings do |t|
$VERBOSE = 1
broken_code
end
他們爲什麼禁用?除了在代碼早期設置VERBOSE=1
之外,是否有簡單的方法來啓用它們?
有趣。介意給你你的耙子和紅寶石版本?我使用的是rake 10.0.3和Ruby 1.9.3p362。謝謝 –
rake 10.0.4和Ruby 2.0.0p247,但是我用rake 0.8.7和Ruby 1.8.7獲得了相同的結果 – Stefan
OK好像是因爲我的rake任務是在Rails .rake文件中定義的,而不是獨立的Rakefile 。我想這是Rails禁用警告而不是Rake。 –