Hello Im trying to write a a ruby program that takes a list of books
title ,author so on and i can read in the file with no problem but im
trying to store the list into either a array or hash so i ca say run
different methods view, delete ect..
anyhelp would be great this is what i have so far
IO.foreach("book_list.txt") do |line|
catalog=line.chomp.split(",")
products.store(items[0].to_i,
[catalog[1],catalog[2].to_i,catalog[3].to_i)
end
ar =
ha = {}
IO.foreach("book_list.txt") do |line|
catalog=line.chomp.split(",")
products.store(items[0].to_i,
[catalog[1],catalog[2].to_i,catalog[3].to_i)
# To array
ar << catalog
# To Hash
ha['some_key'] = catalog
end
It can be done as oneliner:
ar=
File.readlines("book_list.txt").each {|line| ar <<
line.chomp.split(",")}