
Le code :
# Définissons un hachage :
console1 = {
:id => 0,
:name => "wii",
:path => "au magasin" ,
:tags => [:game, :nintendo, :move]
}
# dump : on l'écrit dans fichiertest.yaml
File.open('fichiertest.yaml','w') do |out|
YAML.dump console1, out
end
# On relit avec load
relecteur = open('fichiertest.yaml') do |input|
YAML.load input
end
# Et voilou
for i in relecteur
puts i[0].to_s + " => " + i[1].to_s
end
2 commentaires:
merci pour cet exemple.juste que ce qu'il (me) faut pour commencer un premier fichier en yaml
Euh, oui ? Hé bien ce bout de code génère, si tout va bien, le fichier YAML suivant :
---
:path: au magasin
:name: wii
:id: 0
:tags:
- :game
- :nintendo
- :move
Enregistrer un commentaire