Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Array#abbrev
abbrev(pattern = nil)
lib/abbrev.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/abbrev.rb, line 130
def abbrev(pattern = nil)
Abbrev::abbrev(self, pattern)
end
Calculates the set of unambiguous abbreviations for the strings in self.
Example
require 'abbrev' %w{ car cone }.abbrev #=> {"car"=>"car", "ca"=>"car", "cone"=>"cone", "con"=>"cone", "co"=>"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.
Example
%w{ fast boat day }.abbrev(/^.a/) #=> {"fast"=>"fast", "fas"=>"fast", "fa"=>"fast", "day"=>"day", "da"=>"day"} Abbrev.abbrev(%w{car box cone}, "ca") #=> {"car"=>"car", "ca"=>"car"}
See also Abbrev.abbrev