Home > Rdifflib

Rdifflib

Rdifflib is a project mainly written in Ruby, it's free.

Fork of a port of Python's difflib to Ruby

Python's difflib.get_close_matches for Ruby

Based on this port of python's difflib. The port had 'XXX untested' for the get close matches function.

I added a get best match function, which simply returns the best result.

Documentation

The port code doesn't contain the detailed comments the python version has - maybe I should add them at some point.

Example

(as in http://docs.python.org/library/difflib.html)

irb> require 'rdifflib'
=> true
irb> include Diff
=> Object
irb> Diff.get_close_matches('appel', ['ape', 'apple', 'peach', 'puppy'], n=2, cutoff = 0.6)
=> ["apple", "ape"]
irb> Diff.get_best_match('appel', ['ape', 'apple', 'peach', 'puppy'], cutoff = 0.6) 
=> "apple"