Abbrev

计算为一组给定的字符串集的独特的缩写,也就是。

require 'abbrev'
require 'pp'

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

结果:

{ "rub"   =>  "ruby",
  "ruby"  =>  "ruby",
  "rul"   =>  "rules",
  "rule"  =>  "rules",
  "rules" =>  "rules" }

它也提供了一个数组方法的扩展,Array#abbrev

pp %w{summer winter}.abbrev
#=> {"summe"=>"summer",
     "summ"=>"summer",
     "sum"=>"summer",
     "su"=>"summer",
     "s"=>"summer",
     "winte"=>"winter",
     "wint"=>"winter",
     "win"=>"winter",
     "wi"=>"winter",
     "w"=>"winter",
     "summer"=>"summer",
     "winter"=>"winter"}

天赢金创
338 声望21 粉丝

天赢金创,天赢金创,天赢金创,天赢金创,天赢金创,天赢金创天赢金创,天赢金创


下一篇 »
NEJ _$$Event类

引用和评论

0 条评论