Is there a better way to write this? markdown is a StringIO
coverage_hash_arr = [
{
"Module": "Mobile",
"name": "Sheila Chapman",
"age": 21
},
{
"Module": "Web",
"name": "Hendricks Walton",
"age": 40
},
{
"Module": "Misc",
"name": "Torres Mcdonald",
"age": 39
}
]
coverage_hash_arr.each do |the_hash|
markdown << "------- Status on #{the_hash[:Module]} -------\n"
the_hash.delete(:Module)
the_hash.each {|key, value| markdown << "- #{key}: #{value} \n"}
markdown << "----------------------------------------------\n"
end
I tried this and it seems to work but I wonder if there's a better way (recursion)?
coverage_hash_arr.collect do |the_hash|
the_hash.each do |key,value|
key == :Module ? markdown << "--------- Status for #{value} ----------\n" : markdown << " - #{key}: #{value} \n"
end
markdown << "------------------------------------\n\n"
end
coverage_hash_arrandmarkdownare. What is your input, what is the expected output? Btw are you really still onruby-on-rails-3, are Rails version that is about 8 years old?markdownis a StringIO (specified above) andcoverage_hash_arrwould be an array of hashes."Module"(String) and:Module(Symbol). These two are not equal. You get lucky here because"Module": xdefines a Symbol key, the quotes are extraneous.