aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-22 06:17:42 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-22 06:17:42 +0000
commit4aa91c20eaf9b921eaacbc37c58378623e48e42b (patch)
tree84e909d750524fa0701aa053481eec6e01e98fbe /lib
parentc51c98fd5d87e961034fb19125700f77e35f571c (diff)
downloadruby-4aa91c20eaf9b921eaacbc37c58378623e48e42b.tar.gz
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')
-rw-r--r--lib/csv.rb9
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