From: Peter Bailey Date: 2007-09-22T00:10:39+09:00 Subject: Re: gsub not working. Ruby thinks I'm in an array? Sebastian Hungerecker wrote: > Peter Bailey wrote: >> Here's the lines where this starts: >> registries = [] >> registries = xmlfile.scan(/(.*? )<\/registration>/im) >> #puts registries[100] >> >> registries.sort! >> registries.each do |registry| >> registry.gsub!(/<\/*registrationList>/, "") >> >> Can someone help me understand what's going on here? > > If you have capturing groups in your regexp, scan will return an array > of > arrays, so you are indeed calling gsub! on the subarrays. So either > iterate > over registries.flatten or call gsub! on registry[0] instead of > registry. > > > HTH, > Sebastian Thanks, Sebastian. OK, I did a .flatten, which I read more about and looks like a very cool method. Now, I don't get an error message, but, I don't get any substitutions either! You suggest doing a gsub! on registry[0], but, that's just the first entry. What about the hundreds more I need to work on? I need to keep the sub-groups discrete, because, I'm going to need to sort them, again, based on criteria at the bottom of each group. -Peter -- Posted via http://www.ruby-forum.com/.