0
0

More than 1 year has passed since last update.

#Ruby のあれなんだっけ? 配列からCSVの文字列やインスタンスを生成する、元に戻す

Last updated at Posted at 2020-01-30
require 'csv'

csv_strings = CSV.generate { |csv| csv << ['A', 'B']; csv << ['C', 'D'] }
# => "A,B\nC,D\n"

CSV.new(csv_strings)
# => <#CSV io_type:StringIO encoding:ASCII-8BIT lineno:0 col_sep:"," row_sep:"\n" quote_char:"\"">

CSV.new(csv_strings).read
# => [["A", "B"], ["C", "D"]]

Ref

Class: CSV (Ruby 2.6.1)
https://ruby-doc.org/stdlib-2.6.1/libdoc/csv/rdoc/CSV.html

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0