Need to print the following hash into a txt files with each key as the file name and each key's values as the content for each file.
hash
{ 'a' => [ 'abc' , 'def', 'ghi'] , 'b' => [ 'jkl' , 'mno' , 'pqr' ] }
The output files shall have the following format
a.txt
abc
def
ghi
b.txt
jkl
mno
pqr
Wondering how to go about this?
or just
Try something like:
I'd use
File.write
:Or:
If you want a carriage return at the end of the final line, then one of the answers using
puts
in a loop will work. Some applications care whether there is a trailing line-ending, others don't.