我正在尝试使用 CSV
库从解析 CSV 文件中获取哈希数组。
目前我有一个可以工作的方法:
def rows
rows = []
CSV.foreach(@csv_file.path, headers: true) do |row|
rows << row.to_hash
end
rows
end
但是,当我将它改为这样时,会出现流已关闭
的错误。
def rows
CSV.foreach(@csv_file.path, headers: true).map(&:to_hash)
end
感谢您的提问。