According to file -I file.csv this file is recognized as application/octet-stream; charset=binary because it is missing the BOM information.
According to Wikipedia https://en.wikipedia.org/wiki/UTF-16 it should contain "\xFF\xFE" on the beginning of the document so that everyone knows iths UTF-16LE.
## Adds BOM, albeit in a somewhat hacky way.new_html_file=File.open(foo.txt,"w:UTF-8")new_html_file<<"\xFF\xFE".force_encoding('utf-16le')+some_text.force_encoding('utf-8').encode('utf-16le')
csv.rb seems having bugs in ASCII-incompatible encodings support.
According to file -I file.csv this file is recognized as application/octet-stream; charset=binary because it is missing the BOM information.
According to Wikipedia https://en.wikipedia.org/wiki/UTF-16 it should contain "\xFF\xFE" on the beginning of the document so that everyone knows iths UTF-16LE.
CSV.generate just builds a CSV string, doesn't create a file.
Writing the result to a file with BOM is an application's responsibility.