ヘッダー行のみを含む新しいCSVオブジェクトを作成しようとしていますが、次のコマンドを呼び出すまでヘッダーは設定されませんread()
。
[32] pry(main)> c = CSV.new("Keyword,Index,Page,Index in Page,Type,Title,URL", :headers => :first_row, :write_headers => true, :return_headers => true)
=> <#CSV io_type:StringIO encoding:UTF-8 lineno:0 col_sep:"," row_sep:"\n" quote_char:"\"" headers:true>
[33] pry(main)> c.headers
=> true
[34] pry(main)> c.read
=> #<CSV::Table mode:col_or_row row_count:1>
[35] pry(main)> c.headers
=> ["Keyword", "Index", "Page", "Index in Page", "Type", "Title", "URL"]
何故ですか?1行で正しく機能するCSVオブジェクトを取得できないのはなぜCSV.new
ですか?