diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-22 06:17:42 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-22 06:17:42 +0000 |
commit | 9c38a08f2872f63076988ba8959e3b447cd4a8ce (patch) | |
tree | 84e909d750524fa0701aa053481eec6e01e98fbe /lib/csv.rb | |
parent | 2c69f7b278b782b2243fd9eec71264d4d7cab78c (diff) |
Fixed to write_headers option behavior when given no rows.
[Bug #9988][ruby-core:63375]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/csv.rb')
-rw-r--r-- | lib/csv.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index 25f2bf35e6..45a087ff0f 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1561,6 +1561,12 @@ class CSV # track our own lineno since IO gets confused about line-ends is CSV fields @lineno = 0 + + # make sure headers have been assigned + if header_row? and [Array, String].include? @use_headers.class and @write_headers + parse_headers # won't read data for Array or String + self << @headers + end end # @@ -1677,9 +1683,8 @@ class CSV # def <<(row) # make sure headers have been assigned - if header_row? and [Array, String].include? @use_headers.class + if header_row? and [Array, String].include? @use_headers.class and !@write_headers parse_headers # won't read data for Array or String - self << @headers if @write_headers end # handle CSV::Row objects and Hashes |