From: "Jesús Gabriel y Galán" Date: 2011-02-15T19:05:48+09:00 Subject: Re: Hash sanitization from query - newbie On Tue, Feb 15, 2011 at 10:51 AM, Sem Ptiri wrote: > If I have the following: > > [[148,"Uneducated"],[135,"Highschool"],[272,"Some > college"],[141,"University"],[143,"Post-grad"],[144,"PhD"],[141,"other"],[8,"Post-doc"]] > > is there an function to invert/swap the numbers with strings? Take a look at map or map! (if you want to modify the object in place): irb(main):005:0> a = [[148,"Uneducated"],[135,"Highschool"],[272,"Some college"],[141,"University"],[143,"Post-grad"],[144,"PhD"],[141,"other"],[8,"Post-doc"]] => [[148, "Uneducated"], [135, "Highschool"], [272, "Some college"], [141, "University"], [143, "Post-grad"], [144, "PhD"], [141, "other"], [8, "Post-doc"]] irb(main):006:0> a.map {|(num,string)| [string,num]} => [["Uneducated", 148], ["Highschool", 135], ["Some college", 272], ["University", 141], ["Post-grad", 143], ["PhD", 144], ["other", 141], ["Post-doc", 8]] Jesus.