module Text::Levenshtein
Public Instance Methods
distance(str1, str2, max_distance = nil)
click to toggle source
Calculate the Levenshtein
distance between two strings str1
and str2
.
The optional argument max_distance can reduce the number of iterations by stopping if the Levenshtein
distance exceeds this value. This increases performance where it is only necessary to compare the distance with a reference value instead of calculating the exact distance.
The distance is calculated in terms of Unicode codepoints. Be aware that this algorithm does not perform normalisation: if there is a possibility of different normalised forms being used, normalisation should be performed beforehand.
# File lib/text/levenshtein.rb, line 29 def distance(str1, str2, max_distance = nil) if max_distance distance_with_maximum(str1, str2, max_distance) else distance_without_maximum(str1, str2) end end