Project

General

Profile

Actions

Bug #15872

closed

CSV.parse omits close call when block is given – intended or bug?

Added by sos4nt (Stefan Schüßler) over 5 years ago. Updated over 5 years ago.

Status:
Rejected
Target version:
-
[ruby-core:92817]

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

Also available in: Atom PDF

Like0
Like0Like0Like0