【发布时间】:2014-04-20 04:59:11
【问题描述】:
我正在尝试打开告诉 Ruby 1.9.3 将它们视为 UTF-8 编码的文件。
require 'pathname'
Pathname.glob("/Users/Wes/Desktop/uf2/*.ics").each { |f|
puts f.read(["encoding:UTF-8"])
}
类文档经历了几个间接级别,所以我不确定我是否正确指定了编码。但是,当我尝试它时,我会收到此错误消息
ICS_scanner_strucdoc.rb:4:in read': can't convert Array into Integer (TypeError)
from ICS_scanner_strucdoc.rb:4:inread'
来自 ICS_scanner_strucdoc.rb:4:in block in <main>'
from ICS_scanner_strucdoc.rb:3:ineach'
来自 ICS_scanner_strucdoc.rb:3:in `'
这个错误消息让我相信 read 试图将 open_args 解释为可选的前导参数,这将是读取的长度。
如果我将可选参数放入,如 puts f.read(100000, 0, ["encoding:UTF-8"]) ,我会收到一条错误消息,指出参数太多。
仅指定编码的适当方法是什么?说这是文档和类行为之间的不一致是否正确?
Mac OS 10.8 rvm 当前报告“ruby-1.9.3-p484”
【问题讨论】: