Last active
November 14, 2021 00:30
-
-
Save romeuhcf/29132ebd3084b14901f8770f3baac3bf to your computer and use it in GitHub Desktop.
Ruby 2.5 support for opening csv with bom|utf-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CSV | |
def self.open(file, options={}, &block) | |
encoding = options.delete(:encoding) | |
File.open(file, "r:#{encoding}") do |fd| | |
yield CSV.new(fd, options) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@romeuhcf, isn't it true that your
options
on line 5 already is lacking the:encoding
entry because yourdelete
on line 3 popped it out? Also,:except
is only a Rails method ofHash
, not present in vanilla Ruby.