ruby - How can I read multiple documents from a YAML file? -


i want make yaml file consists of hashes. however, cannot iterate on it. when try load yaml file with:

yaml.load_file('yamlfile.yml')  

it returns first hash in file. here example file create:

--- :reach_hypo: true :liquid: true --- :reach_hypo: true :liquid: false --- :reach_hypo: true :liquid: true  

if load above file, get:

{reach_hypo: true, liquid: true} 

the workaround have found add hashes array, write yaml file. there better way, such yaml method, iterate on yaml file?

read multiple yaml documents single file streams

you can use yaml::load_stream read multiple documents single file. example:

require 'yaml'  array = [] yaml.load_stream(file.read 'test.yml') { |doc| array << doc } array  #=> [{:reach_hypo=>true, :liquid=>true}, {:reach_hypo=>true, :liquid=>false}, {:reach_hypo=>true, :liquid=>true}] 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -