I ve got a yaml file document which have similar keys :-
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
在编造新档案之后。 key 钥匙按字母顺序分类:
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
开放式样本-档案和制作新档案的代码如下:
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 ]))