From: Matt Armstrong Date: 2002-12-17T03:01:41+09:00 Subject: Re: Splitomania - advice welcome Anders Engstr�m writes: > def editors > if @editors == nil > @editors = Hash.new > fileattr = "#{@cvswd}/CVS/fileattr" > if File.exist?(fileattr) > File.open(fileattr){ |file| > line = nil > file.each_line { |l| line = l if l =~ /^F#{name}/ } > if line != nil > line.split("\t").last.split(";").each { |attpair| > next unless attpair =~ /^_editors=(.+)/ > $1.split(",").each { |editor| > name, stuff = editor.split(">") > @editors[name] = stuff > } > } > end > } > end > end > return @editors > end It looks like you are using 'name' before initializing it. Also, File.exit? doesn't mean File.open will succeed. I would use begin/rescue/end if you want to succeed when the file is not there. E.g. begin rescue Errno::ENOENT end > the code is implemented in an accessor method (I don't know if the > above is the prefered way to implement 'lazy loading' in Ruby - > comments are welcome :). Yes, I've done that. There is also the memoize package. http://www.ruby-lang.org/raa/list.rhtml?id=34