Saturday, August 11, 2012

Ruby programming !sort


I was searching for a quick way to sort objects in Ruby and I found this ingenious method online.
deviceArray.sort! {|a,b| a.getName.downcase <=> b.getName.downcase}

notes
deviceArray : an array of objects of type device
downcase : only needed if sorting alpa numerically or can use upcase

No comments:

Post a Comment