abbrev

abbrev(words, pattern = nil)
Class Public methods

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(['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}, /b/)
#=> {"bo"=>"box", "b"=>"box", "box"=>"box"}
doc_ruby_on_rails
2015-03-30 01:25:40
Comments
Leave a Comment

Please login to continue.