From: Robert Klemme Date: 2007-07-26T20:01:58+09:00 Subject: Re: List of directory. 2007/7/26, Marcin Tyman : > Hi, > > Does anybody know how to list directory in alphabetical order? i.e. > I have following files: > a10 > a1 > a2 > a20 > > sort method sorts them as follows: > > a1 > a10 > a2 > a20 > > but I need such order: > > a1 > a2 > a10 > a20 Apparently you want to _sort by_ the numeric part. You can extract it with a regular expression like this: irb(main):017:0> a.sort_by {|x| x[/\d+/].to_i } => ["a1", "a2", "a10", "a20"] Kind regards robert