require 'csv' require 'yaml' require 'pp' path_to_csv = 'score.csv' path_to_yaml = 'score.yaml' csv = CSV.read(path_to_csv, :headers => true).map(&:to_hash) hash = csv File.open(path_to_yaml, 'w') { |f| f.write(hash.to_yaml) } pp YAML.load_file(path_to_yaml)
![CSV ファイルを YAML ファイルへ変換する | DriftwoodJP](https://cdn-ak-scissors.b.st-hatena.com/image/square/dbe0b1f80a9cba330c14ce2f03c29faa6f986d6f/height=288;version=1;width=512/https%3A%2F%2Fwww.d-wood.com%2Fwpmt%2Fwp-content%2Fthemes%2Fdeadwood2%2Fimg%2Fog_image.jpg)