У меня есть документ в файле yaml с похожими ключами: -
sample_file.yml
line:
title: line-name
department: transcription
input_formats:
- input_format:
name: company
required: true
valid_type: general
- input_format:
name: website
required: false
valid_type: url
После генерации new_file.yml ключи сортируются в алфавитном порядке: -
new_file.yml
line:
department: transcription
input_formats:
-
input_format:
name: company
required: true
valid_type: general
-
input_format:
name: website
required: false
valid_type: url
title: line-name
код для открытия sample_file и создания нового_файла ниже: -
require 'yaml'
require 'ya2yaml'
@file = YAML::load(File.open("/Users/manish/Desktop/yaml/sample_file.yml"))
@new_file = File.new("/Users/manish/Desktop/yaml/new_file.yml", "w+")
@new_file.syswrite(@file.ya2yaml(:hash_order => ['title','department','input_formats']))
Я использую гем "ya2yaml" для создания файла yaml. Чтобы получить тот же порядок, что и в sample_file.yml, я использовал здесь hash_order @new_file.syswrite(@file.ya2yaml(:hash_order => ['title','department','input_formats']))
, но он не работает. Как я могу сохранить заказ?