DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Using Array#abbrev

06.04.2010
| 1585 views |
  • submit to reddit
        <snip>Calculates the set of unambiguous abbreviations for the strings in self. If passed a pattern or a string, only the strings matching the pattern or starting with the string are considered. 
require 'abbrev'

%w{ car cone }.abbrev
#=> {"ca"=>"car", "con"=>"cone", "co"=>"cone", "car"=>"car", "cone"=>"cone"}
</snip>
Resources:
 - <a href="http://apidock.com/ruby/Array/abbrev">abbrev (Array)</a> [apidock.com]