On Dec 20, 2006, at 10:05 AM, Josselin wrote:

> all happy visitors of Paris know about the 'arrondissement', an  
> administrative division of the city...  20 divisions
>
> selecting them from a city table I can map them as :
>
> ['Paris 1'  , 'Paris 10' , 'Paris 11' , .....  'Paris 19' , 'Paris  
> 2' , 'Paris 20' , 'Paris 3' , .... 'Paris 9' ]
 >> paris = (1..20).map {|i| "Paris #{i}"}.sort
=> ["Paris 1", "Paris 10", "Paris 11", "Paris 12", "Paris 13", "Paris  
14", "Paris 15", "Paris 16", "Paris 17", "Paris 18", "Paris 19",  
"Paris 2", "Paris 20", "Paris 3", "Paris 4", "Paris 5", "Paris 6",  
"Paris 7", "Paris 8", "Paris 9"]

> is there any way to sort this array and get :
>
> ['Paris 1'  , 'Paris 2' , 'Paris 3' , .... 'Paris 9' , 'Paris 10' ,  
> 'Paris 11' , .....  'Paris 19' , 'Paris 20' ]
>
> which seems betetr in a list... ;-))
>
> thanks for your light
>
> joss

 >> paris.sort_by { |division| division.match(/(\d+)/)[1].to_i }
=> ["Paris 1", "Paris 2", "Paris 3", "Paris 4", "Paris 5", "Paris 6",  
"Paris 7", "Paris 8", "Paris 9", "Paris 10", "Paris 11", "Paris 12",  
"Paris 13", "Paris 14", "Paris 15", "Paris 16", "Paris 17", "Paris  
18", "Paris 19", "Paris 20"]

if you have other cities or more than one embedded number, this is  
likely too simple, but it works for your example.

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com