Disposable Not Disposed (ARCH6080)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key ruby.performance.disposable-not-disposed · Severity error · Category performance
A closeable resource created without the block form is left open and leaks if an exception is raised. Wrap the resource in the block form so it closes automatically.
Incorrect
Section titled “Incorrect”def write_report(path, data) file = File.open(path, "w") file.write(data) file.closeendCorrect
Section titled “Correct”def write_report(path, data) File.open(path, "w") do |file| file.write(data) endendWrap the resource in the block form instead of opening and closing it manually; it closes when the block ends.