From: Daniel Harple Date: 2005-12-31T14:24:36+09:00 Subject: Re: Another Newb asks questions. Joseph Divelbiss wrote: > Thanks again all.. so that you know your efforts wern't in vain I > think > I learned a thing or two. The rough code (still needing debugging > about > as much as I need sleep) is below. I have a high level of confidence > that I will find the typo or missing end to make it work when I > wake up > in the morning. > > require 'enumerator' > if Dir["#{$script_dir}data/"].last != nil > script_data_dir = "#{$script_dir}data/" > end > build_hash = Proc.new do |type| > type_hash = Hash.new > file.open("#{script_data_dir}#{type}.dat", "r") do |file| > file.each_slice(2) do |key, value| > type_hash[key.chomp] = value.chomp > end > end > $type_hash = type_hash > end > data_files=Dir["#{script_data_dir}*.dat"] > data_files.each do |name_of_file| > build_hash.call(file.basename(name_of_file, '*.*')) > end > > VR, > > Joseph > > -- > Posted via http://www.ruby-forum.com/. I see two typos -- 1) file.open should be File.open ( actually, you can leave off File too, so it is just open(..). See Kernel#open ). 2) file. basename should be File.basename Slight style suggestions -- * The first conditional statement may be rewrote as: script_data_dir = "#{$script_dir}data/" unless Dir["#{$script_dir} data/"].last.nil? * {} is equivalent to Hash.new * Use { |x| ... } block syntax when the block has only one simple statement (the each_slice part) -- Daniel