2013-07-05 34 views
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之外,是否有簡單的方法來啓用它們?

回答

2

它爲我的作品:

# Rakefile 
task :foo do |t| 
    File.new {} 
end 

結果:

$ rake foo 
(in /tmp) 
/tmp/Rakefile:2: warning: File::new() does not take block; use File::open() instead 
rake aborted! 
+0

有趣。介意給你你的耙子和紅寶石版本?我使用的是rake 10.0.3和Ruby 1.9.3p362。謝謝 –

+0

rake 10.0.4和Ruby 2.0.0p247,但是我用rake 0.8.7和Ruby 1.8.7獲得了相同的結果 – Stefan

+0

OK好像是因爲我的rake任務是在Rails .rake文件中定義的,而不是獨立的Rakefile 。我想這是Rails禁用警告而不是Rake。 –

相關問題