views:

59

answers:

1

How do I sort this:

arr = ["aaa","aa","aaaa","a","aaaaa"];

into this

arr = ["a","aa","aaa","aaaa","aaaaa"];
+5  A: 
arr = arr.sort_by {|x| x.length}

Or in 1.8.7+:

arr = arr.sort_by(&:length)
sepp2k