summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKoichi ITO <koic.ito@gmail.com>2020-06-02 08:30:25 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-07-20 02:32:51 +0900
commit4e33a878793a5ced47a4f14b8a73cbc2795d97b7 (patch)
treecd3173a3b2dbbe97d84e800598a874c8620d00bf /lib
parentcf8157e0016dd0eb60fe6f03bef168261f729b83 (diff)
downloadruby-4e33a878793a5ced47a4f14b8a73cbc2795d97b7.tar.gz
[ruby/csv] Add `undef: :replace` for `CSV.open` (#129)
This PR adds `undef: :replace` option for `CSV.open`. `File.open` has `undef: :replace` option, but `CSV.open` does not. It would be convenient if `CSV.open` could have a shortcut by having `undef: :replace` option. https://github.com/ruby/csv/commit/cff8b18480
Diffstat (limited to 'lib')
-rw-r--r--lib/csv.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/csv.rb b/lib/csv.rb
index 4ffffe4056..a06c92a1b9 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -960,6 +960,11 @@ class CSV
# open( filename, mode = "rb", **options )
# open( filename, **options )
#
+ # possible options elements:
+ # hash form:
+ # :undef => :replace # replace undefined conversion
+ # :replace => string # replacement string ("?" or "\uFFFD" if not specified)
+ #
# This method opens an IO object, and wraps that with CSV. This is intended
# as the primary interface for writing a CSV file.
#
@@ -1021,6 +1026,8 @@ class CSV
# wrap a File opened with the remaining +args+ with no newline
# decorator
file_opts = {universal_newline: false}.merge(options)
+ options.delete(:undef)
+ options.delete(:replace)
begin
f = File.open(filename, mode, **file_opts)