From: Stuart Little Date: 2009-02-12T07:33:07+09:00 Subject: Re: Array uniq That makes sense but how do I avoid this? I cant see how. I need to dedupe before the data goes into @alerts. David A. Black wrote: > Hi -- > > On Thu, 12 Feb 2009, Stuart Little wrote: > >> Is returned after my code exactly the same, I am expecting >> >> WedAug062008 >> TueAug052008 >> >> I have dumbed the code down to see what you think: >> >> time = event.time_written.to_s >> dateCheck = [time.gsub(/\s/, '')[0..7] + time[26..29]] >> printdata = [dateCheck] >> @alerts.push printdata.uniq > > printdata.uniq is the same items as printdata, because printdata only > contains one item. So you're doing this: > dateCheck = ["string"] > printdata = [["string"]] > @alerts.push [["string"]].uniq > I don't how deeply nested you want your arrays, but if @alerts is the > final product and you want it uniq, you could run @alerts.uniq! at the > end, or do something like: > @alerts.push printdata unless @alerts.include?(printdata) > David > -- > David A. Black / Ruby Power and Light, LLC > Ruby/Rails consulting & training: http://www.rubypal.com > Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) > > http://www.wishsight.com => Independent, social wishlist management! -- Posted via http://www.ruby-forum.com/.