[RCR] natcmp.rb added to string class

M

Michael Neumann

Patrick said:
Hello,

Natural Order String Comparison is a useful algorithm:

http://sourcefrog.net/projects/natsort/

Alan Davies wrote an implementation of the algorithm in ruby, and it is
useful:

http://sourcefrog.net/projects/natsort/natcmp.rb

I think it would be nice if String always had this method. I hope there
aren't license conflicts.

Hm, I think it's good to have this as an external library. This could
then extend both String and Array classes. E.g.

require 'natsort'

["a10", "a2"].sort {|a,b| a.natcmp(b) }
# or
["a10", "a2"].natsort

Regards,

Michael
 
P

Patrick May

Hello,

Hm, I think it's good to have this as an external library. This could
then extend both String and Array classes. E.g.

require 'natsort'

["a10", "a2"].sort {|a,b| a.natcmp(b) }
# or
["a10", "a2"].natsort

The only reason I think that this would be better as a standard
library, instead of being directly on String and Array, is that it
would be easier to maintain the code. From a user point of view, I'd
like those functions to just be on String.

Cheers,

Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top