Actions
Bug #15872
closedCSV.parse omits close call when block is given – intended or bug?
Bug #15872:
CSV.parse omits close call when block is given – intended or bug?
Description
The current implementation of CSV.parse doesn't call close when a block is given:
def self.parse(*args, &block)
csv = new(*args)
return csv.each(&block) if block_given?
begin
csv.read
ensure
csv.close # <- never gets here if block is given
end
end
A possible fix would be:
def self.parse(*args, &block)
csv = new(*args)
if block_given?
csv.each(&block)
else
csv.read
end
ensure
csv.close
end
But I'm not sure if this behavior might be intended, given that Ruby's CSV library is quite mature.
Am I missing a use case or is this actually a bug?
Actions