From: Kev Date: 2007-03-09T18:20:05+09:00 Subject: Re: File open, read and store in Hash, efficient? On 9 Mar, 09:12, "Kev" wrote: > Hello, > > I am writing a class and I require it to open a file, and store the > contents in key, value pairs. > This is my first > > def initialize() > @@store = Hash.new > end > > def read_file > if File.exists?("LocationCopy.csv") > f = File.open("LocationCopy.csv","r") > f.each do |line| > temp = line.split(",") > @@store[temp[0]] = temp[1] > end > f.close > end > #puts @@store > end Unfortunately thats what I call finger trouble, as I was saying this is my first attempt at a Ruby application and was wondering if there is a more efficient method for what I am trying to achieve. Would using f.each_line and using a block be better? Thanks, Kev