samedi 31 mai 2014

How do I print the values of hashsets that are saved in a file in ruby


Vote count:

0




well I have file(named ter.txt) that contains the hashsets below as content ;



{"qty"=>"gfg", "unit"=>"gfg", "item"=>"xcv", "cost"=>"0.0", "salestax"=>"0.0"}
{"qty"=>"gdf", "unit"=>"g", "item"=>"gg", "cost"=>"0.0", "salestax"=>"0.0"}


i want to print the values of the above hashsets.I tried doing the following but i got an error of undefined local variable or method 'item'



file = File.open('ter.txt', 'r').map { |line| line.split("\n")[0] }


file.each do |hash|
p hash
p " #{hash[item]}"
end


asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire