diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-25 07:44:50 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-25 07:44:50 +0000 |
commit | 9a907880f05fef475d5b61ed7f03f045b6103ed8 (patch) | |
tree | ca5ec83cb5f7e3befaaa92f293a63f1c3301d7eb /lib/csv.rb | |
parent | b4876f5e0422e020d617b77145a492c5bc327f08 (diff) | |
download | ruby-9a907880f05fef475d5b61ed7f03f045b6103ed8.tar.gz |
* lib/csv.rb (CSV::foreach, CSV#initialize): fixed passing options.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/csv.rb')
-rw-r--r-- | lib/csv.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index 266810cb93..092424e33c 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1335,9 +1335,9 @@ class CSV # find the +options+ Hash options = if args.last.is_a? Hash then args.pop else Hash.new end # default to a binary open mode - args << "rb" if args.size == 1 + args << "rb" if args.size == 1 and !options.key?(:mode) # wrap a File opened with the remaining +args+ - csv = new(File.open(*args), options) + csv = new(File.open(*args, options), options) # handle blocks like Ruby's open(), not like the CSV library if block_given? @@ -1561,7 +1561,11 @@ class CSV # create the IO object we will read from @io = data.is_a?(String) ? StringIO.new(data) : data # honor the IO encoding if we can, otherwise default to ASCII-8BIT - @encoding = options.delete(:internal_encoding) || options.delete(:encoding) || + @encoding = options.delete(:internal_encoding) || + (case encoding = options.delete(:encoding) + when Encoding; encoding + when /\A[^:]+/; $1 + end) || raw_encoding || Encoding.default_internal || Encoding.default_external # @@ -1579,6 +1583,9 @@ class CSV init_converters(options) init_headers(options) + options.delete(:encoding) + options.delete(:internal_encoding) + options.delete(:external_encoding) unless options.empty? raise ArgumentError, "Unknown options: #{options.keys.join(', ')}." end |