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コードの早い段階で設定する以外に、それらを有効にする簡単な方法はありますか?

4

1 に答える 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!
于 2013-07-05T13:44:05.590 に答える