Issue #17430 has been updated by kou (Kouhei Sutou).

Assignee set to kou (Kouhei Sutou)
Status changed from Open to Closed

It has been fixed in the latest csv gem.

You can use update your csv by `gem install csv`.

----------------------------------------
Bug #17430: CSV: NoMethodError when the write_nil_value or write_empty_value options are used
https://bugs.ruby-lang.org/issues/17430#change-89435

* Author: Soilent (Konstantin x)
* Status: Closed
* Priority: Normal
* Assignee: kou (Kouhei Sutou)
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
CSV.generate_line throws an exception when I specify `write_nil_value` or `write_nil_value`.

```
> CSV.generate_line [1,nil,3]
=> "1,,3\n"
> CSV.generate_line [1,nil,3], write_nil_value: 'x'
Traceback (most recent call last):
       12: from /usr/bin/irb:23:in `<main>'
       11: from /usr/bin/irb:23:in `load'
       10: from /usr/lib/ruby/gems/2.7.0/gems/irb-1.2.7/exe/irb:11:in `<top (required)>'
        9: from (irb):3
        8: from (irb):4:in `rescue in irb_binding'
        7: from /usr/lib/ruby/2.7.0/csv.rb:569:in `generate_line'
        6: from /usr/lib/ruby/2.7.0/csv.rb:1230:in `<<'
        5: from /usr/lib/ruby/2.7.0/csv/writer.rb:44:in `<<'
        4: from /usr/lib/ruby/2.7.0/csv/fields_converter.rb:50:in `convert'
        3: from /usr/lib/ruby/2.7.0/csv/fields_converter.rb:50:in `with_index'
        2: from /usr/lib/ruby/2.7.0/csv/fields_converter.rb:50:in `collect'
        1: from /usr/lib/ruby/2.7.0/csv/fields_converter.rb:53:in `block in convert'
NoMethodError (undefined method `empty?' for 1:Integer)
> CSV.generate_line [1,nil,3], write_empty_value: 'x'
NoMethodError (undefined method `empty?' for 1:Integer)
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>