|
|
|
|
|
by rst
5529 days ago
|
|
And there actually is an idiomatic way to avoid the problem in Ruby: File.open("...") do |f|
firstline = f.readline
... stuff that might throw an exception ...
end
If the "stuff" throws an exception, the file gets closed automatically. And while File is a library class, it's getting no special favors here --- any pure ruby library can easily implement similar APIs, and ActiveRecord's connection pool, for example, actually does. |
|