Failed to allocate memory error

Hi, all. I just found Ruby two days ago and I’m extremely impressed with its power and consistency. I wrote a quick script tonight to go through all the MP3 files in my music directory and see if their tag information matches the file name. If the two don’t match, the file is renamed to reflect the contents of the tag.

It works perfectly, but after a couple of minutes, I get this:

failed to allocate memory
[FATAL] failed to allocate memory

As I’ve mentioned, I’m extremely new to Ruby, so perhaps there’s something wrong with my code. I’ve included my code below.

Thanks for your help,
Bill

require 'mp3info’
require ‘find’

Find.find(’./music’) do |mp3|
next if FileTest.directory?(mp3) or not mp3.scan(/.mp3$/)
orig_name = mp3.split("/")[-1].gsub(/.mp3/, “”)
begin
m = Mp3Info.new(mp3)
taghash = if m.hastag2?
taghash = m.tag2
elsif m.hastag1?
taghash = m.tag1
else
taghash = nil
end
next unless taghash and taghash[‘artist’] and taghash[‘title’]
correct = taghash[‘artist’] + " - " + taghash[‘title’]
if orig_name != correct
final_path = mp3.gsub /#{orig_name}/, correct
puts "#{mp3} ----> #{final_path}\n----\n"
File.rename(mp3, final_path)
end
rescue Exception => e
puts e.to_s
end
end

···

No banners. No pop-ups. No kidding.
Introducing My Way - http://www.myway.com