From: Robert Dober Date: 2007-05-20T03:54:12+09:00 Subject: Re: A place for an "edit_distance" method On 5/19/07, Eli Bendersky wrote: > Hi all, > > In my application I need an "edit_distance" method that computes the > Edit Distance (Also called Levenshtein Distance, see this: > http://en.wikipedia.org/wiki/Levenshtein_distance) between two > strings. I wonder where is the right place to put this method. I have > a "utils" Ruby file with various extensions to classes and modules > that make my life easier. So there are two options: > > 1) Have a global (Kernel) method named "edit_distance" that accepts > two strings Crouding the global namespace -1, but if you feel it is convenient. > 2) Add a "edit_distance_from" method to the String class that accepts > the "other" string Why not, just that I believe extending core classes shall be done under one of two conditions, (a) not an API just your program or (b) just that API IOW, your package just does this and the extension is well documented. 3) Create an extension module with a module method edit_distance( str1, str2) Cheers Robert > > Which approach is better, in your opinion ? > > P.S: There are lots of Edit Distance implementations in Ruby online. > For example: > http://db.cs.helsinki.fi/~jaarnial/mt/archives/000074.html > http://ruby.brian-schroeder.de/editierdistanz/ > > > -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw