method
abbrev
v2_5_5 -
Show latest stable
-
0 notes -
Class: Abbrev
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378 (0)
- 1_9_2_180 (0)
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (38)
- 2_2_9 (18)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
abbrev(words, pattern = nil)
public
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 words is “car” and “cone”, the keys pointing to “car” would be “ca” and “car”, while those pointing to “cone” would be “co”, “con”, and “cone”.
require 'abbrev' Abbrev.abbrev(%w{ car cone }) #=> {"ca"=>"car", "con"=>"cone", "co"=>"cone", "car"=>"car", "cone"=>"cone"}
The optional pattern parameter is a pattern or a string. Only input strings that match the pattern or start with the string are included in the output hash.
Abbrev.abbrev(%w{car box cone crab}, /b/) #=> {"box"=>"box", "bo"=>"box", "b"=>"box", "crab" => "crab"} Abbrev.abbrev(%w{car box cone}, 'ca') #=> {"car"=>"car", "ca"=>"car"}