[#77789] [Ruby trunk Feature#12012] Add Boolean method — prodis@...
Issue #12012 has been updated by Fernando Hamasaki de Amorim.
4 messages
2016/10/27
[ruby-core:77623] [Ruby trunk Feature#12839] CSV - Give not nil but empty strings for empty fields
From:
5.5@...
Date:
2016-10-14 05:45:14 UTC
List:
ruby-core #77623
Issue #12839 has been reported by 5 5.
----------------------------------------
Feature #12839: CSV - Give not nil but empty strings for empty fields
https://bugs.ruby-lang.org/issues/12839
* Author: 5 5
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
The CSV parser gives nil for empty fields.
```rb
require "csv"
CSV.parse(%|,""|) #=> [[nil, ""]]
```
The above behavior maybe be suitable for certain programmers, but I hope to get `[["", ""]]`.
So I had used to write the following code reluctantly till Ruby 2.1:
```rb
require "csv"
CSV.parse(%|,""|, converters: lambda{|v| v || ""})
#=> [["", ""]]
```
It is wasteful, but certainly works for my purpose.
However, because of #11126, the above code does not work from Ruby 2.2.
(Converters are not called for nil)
I merely want an option, which makes the CSV parser give empty strings for empty fields.
Namely,
```rb
require "csv"
CSV.parse(%|,""|, string: true) #=> [["", ""]]
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>