Actions
Bug #12100
closedCSV converters fail when using single arg proc
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
all versions 2.0, 2.1, 2.2, 2.3, trunk
Description
CSV#parse (and others) throw an ArgumentError when passing a single argument Proc as a converter because of a performance optimization check that assumes Proc#arity is always positive. Lambdas with one argument work fine as do Procs and lambdas with two arguments. The documentation suggests to me that either should work. Supporting the Proc variant is trivial and allows to_proc and to_proc shortcut syntax to be used eliminating the surprising behavior and uninformative error message. Illustration of the problem is below and a patch with tests is attached. I'm also creating a PR on Github because I think this is a minor enough change to be merged quickly. Thank you.
require 'csv'
puts CSV.parse(" foo , bar ", converters: -> f { f.strip }).inspect
puts CSV.parse(" foo , bar ", converters: :strip.to_proc).inspect
# Without patch this outputs:
# [["foo", "bar"]]
# /home/mdaubert/.rbenv/versions/2.3.0/lib/ruby/2.3.0/csv.rb:2205:in `strip': wrong number of arguments (given 1, expected 0) (ArgumentError)
# With patch this outputs:
# [["foo", "bar"]]
# [["foo", "bar"]]
Files
Actions
Like0
Like0Like0Like0Like0Like0