Skip to content

Instantly share code, notes, and snippets.

@romeuhcf
Last active November 14, 2021 00:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save romeuhcf/29132ebd3084b14901f8770f3baac3bf to your computer and use it in GitHub Desktop.
Save romeuhcf/29132ebd3084b14901f8770f3baac3bf to your computer and use it in GitHub Desktop.
Ruby 2.5 support for opening csv with bom|utf-8
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
@lonniev
Copy link

lonniev commented Nov 12, 2019

@romeuhcf, isn't it true that your options on line 5 already is lacking the :encoding entry because your delete on line 3 popped it out? Also, :except is only a Rails method of Hash, not present in vanilla Ruby.

@romeuhcf
Copy link
Author

@lonniev tks buddy. Just updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment