2013-07-05 38 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。 –

相关问题