Reputation: 305
I would like to write the key value inside file as vals. I hope you can help me about it. Thank you.
File.open(resfile,'a+') do |f2|
gname.each {|key,val| val.each {|x| f2.write(x) f2.write("\t")}
f2.write("\n")}
end
Upvotes: 0
Views: 174
Reputation: 998
I guess what you mean in this:
h = { "v1" => 1, "v2" => 2}
File.open("./out.dat","w") do |f|
h.each { |k,v| f.write("#{k}\t#{v}\n") }
end
Upvotes: 0
Reputation: 121000
result = gname.map { |_key, val| val.join("\t") }.join("\n")
File.write(resfile, result)
Upvotes: 1