Module

Abbrev

Calculate the set of unique abbreviations for a given set of strings.

require 'abbrev'
require 'pp'

pp Abbrev::abbrev(['ruby', 'rules']).sort

Generates:

[["rub", "ruby"],
 ["ruby", "ruby"],
 ["rul", "rules"],
 ["rule", "rules"],
 ["rules", "rules"]]

Also adds an abbrev method to class Array.

Public Methods
abbrev Given a set of strings, calculate the set of unambiguous abbreviations for those strings, and return a hash where the keys are all the possible abbreviations and the values are the full strings. Thus, given input of "car" and "cone", the keys pointing to "car" would be "ca" and "car", while those pointing to "cone" would be "co", "con", and "cone".
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.