字符串不能写入CSV文件Ruby

Ton*_*rez 2 ruby csv arrays

我不一定理解为什么这段代码不正确.我理解该字符串类中的错误没有方法映射.但是我很难绕过这个错误.

错误

`<<': undefined method `map' for #<String:0x000001020b8940> (NoMethodError)
Run Code Online (Sandbox Code Playgroud)

但是代码

require 'nokogiri'
require 'open-uri'
require 'csv'

doc = Nokogiri::HTML(open("dent-file.html"))

new_array = doc.search("p").map do |para|
     para.text
end

CSV.open("dent.csv", "w") do |csv|
   new_array.each do |string|
     csv << string
   end
end
Run Code Online (Sandbox Code Playgroud)

我想将newdoc数组的每个元素写入csv文件dent.csv的每一行.

fal*_*tru 9

CSV#<<接受一个数组或一个CSV::Row.将字符串转换为数组.

csv << [string]
Run Code Online (Sandbox Code Playgroud)