levenshtein
-
This function’s solution requires the text gem.
We can calculate Levenshtein distance between two strings in Ruby with the help of the text gem. To install this gem:
$> sudo gem install Text Successfully installed Text-1.1.2 1 gem installed
PHP
$result = levenshtein('hello', 'world'); var_export($result); // => 4
Ruby
require 'rubygems' require 'text' p Text::Levenshtein.distance('hello', 'world') # => 4
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

