From: Josh Cheek Date: 2011-09-17T14:22:59+09:00 Subject: Re: array.map! + delete_if possible ? --20cf3079bbf87782fd04ad1c4ca5 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Sep 16, 2011 at 5:03 PM, Kassym Dorsel wrote: > I have an array of strings that I need to modify. I either need to > replace the string or delete the entry altogether. The only way I have > been able to do this is : > > > arr.delete("") > > (0..arr.size).each do |i| > if arr[i].to_i == 1201 > arr[i]=arr[i].to_s[8..-1].gsub(/"[^"]*"/,'::').gsub(/".*/,"::") > else > arr[i-1] = arr[i-1] + arr[i].to_s[4..-1].to_s.gsub(/\s*/,"") > arr[i]=nil > end > end > > arr.delete(nil) > > > Is there a better way ? > > > Also inside the else I get char 4->-1 of a string, but then need to > explicitly change it into a string for gsub to work. Otherwise it gives > me an undefined method 'gsub' for nilNilClass error. > > -- > Posted via http://www.ruby-forum.com/. > > I honestly have no idea what this is supposed to do. --20cf3079bbf87782fd04ad1c4ca5--