Unable to headers with only one line no body CSV file in Ruby 2.5
Ruby 2.5
require 'csv'
CSV.parse("A,B,C", headers: true).headers
# => []
CSV.parse("A,B,C\nX,Y,Z", headers: true).headers
# => ["A", "B", "C"]
CSV.parse("A,B,C", headers: true).to_s
# => "\n"
以下で動作確認。
ruby 2.5.2p104 (2018-10-18 revision 65133) [x86_64-darwin18]
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18]
-
ruby 2.5.6p201 (2019-08-28 revision 67796) [x86_64-linux]
(docker+mac)
Ruby 2.6
require 'csv'
CSV.parse("A,B,C", headers: true).headers
# => ["A", "B", "C"]
CSV.parse("A,B,C\nX,Y,Z", headers: true).headers
# => ["A", "B", "C"]
CSV.parse("A,B,C", headers: true).to_s
# => "A,B,C\n"
以下で動作確認。
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18]
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
-
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
(docker+Mac)
Docs
どこに違いがあるのだろう?
https://ruby-doc.org/stdlib-2.5.3/libdoc/csv/rdoc/CSV.html#method-i-headers
https://ruby-doc.org/stdlib-2.6.1/libdoc/csv/rdoc/CSV.html#method-i-headers
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。