本文簡要介紹ruby語言中 Abbrev模塊
的用法。
計算給定字符串集的明確縮寫集。
require 'abbrev'
require 'pp'
pp Abbrev.abbrev(['ruby'])
#=> {"ruby"=>"ruby", "rub"=>"ruby", "ru"=>"ruby", "r"=>"ruby"}
pp Abbrev.abbrev(%w{ ruby rules })
Generates:
{ "ruby" => "ruby",
"rub" => "ruby",
"rules" => "rules",
"rule" => "rules",
"rul" => "rules" }
它還提供了一個陣列核心擴展 Array#abbrev
。
pp %w{ summer winter }.abbrev
Generates:
{ "summer" => "summer",
"summe" => "summer",
"summ" => "summer",
"sum" => "summer",
"su" => "summer",
"s" => "summer",
"winter" => "winter",
"winte" => "winter",
"wint" => "winter",
"win" => "winter",
"wi" => "winter",
"w" => "winter" }
相關用法
- Ruby Abbrev.abbrev用法及代碼示例
- Ruby AbstractSyntaxTree.of用法及代碼示例
- Ruby AbstractSyntaxTree.parse_file用法及代碼示例
- Ruby AbstractSyntaxTree.parse用法及代碼示例
- Ruby Array.push用法及代碼示例
- Ruby Array.hash用法及代碼示例
- Ruby ARGF.path用法及代碼示例
- Ruby Addrinfo.ip_address用法及代碼示例
- Ruby Array permutation()用法及代碼示例
- Ruby Array.to_a用法及代碼示例
- Ruby Array.to_h用法及代碼示例
- Ruby Array.to_s用法及代碼示例
- Ruby Array class fill()用法及代碼示例
- Ruby Array.array + other_array用法及代碼示例
- Ruby Array product()用法及代碼示例
- Ruby Array zip()用法及代碼示例
- Ruby Array concat()用法及代碼示例
- Ruby Array類用法及代碼示例
- Ruby Addrinfo.connect_from用法及代碼示例
- Ruby Array.take()用法及代碼示例
- Ruby Array.reject!用法及代碼示例
- Ruby ASN1Data.new用法及代碼示例
- Ruby Array.flatten!用法及代碼示例
- Ruby Array.reject用法及代碼示例
- Ruby Array compact!()用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Abbrev模塊。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。