abbrev()是一个Array类方法,可为字符串提供明确的缩写集。
用法:Array.abbrev()
参数:–缩写字符串
–模式[可选]
返回:明确的缩写集
示例1:abbrev()方法的示例
# Ruby code for abbrev() method
# checking for unambiguous abbreviations
require 'abbrev'
# different pattern style
puts "abbrevation : #{%w{ hello goa }.abbrev}\n\n"
puts "abbrevation : #{%w{ geeks }.abbrev}\n\n"
输出:
abbrevation : {"hello"=>"hello", "hell"=>"hello", "hel"=>"hello", "he"=>"hello", "h"=>"hello", "goa"=>"goa", "go"=>"goa", "g"=>"goa"} abbrevation : {"geeks"=>"geeks", "geek"=>"geeks", "gee"=>"geeks", "ge"=>"geeks", "g"=>"geeks"}
示例2:abbrev()方法的示例
# Ruby code for abbrev() method
# checking for pattern
require 'abbrev'
# checking pattern
puts "pattern : #{%w{ coat past ray }.abbrev(/^.a/)}\n\n"
puts "pattern : #{Abbrev.abbrev(%w{dropping dropper drop}, "drop")}\n\n"
输出:
pattern : {"past"=>"past", "pas"=>"past", "pa"=>"past", "ray"=>"ray", "ra"=>"ray"} pattern : {"dropping"=>"dropping", "droppin"=>"dropping", "droppi"=>"dropping", "dropper"=>"dropper", "droppe"=>"dropper", "drop"=>"drop"}
相关用法
- Ruby Array take()用法及代码示例
- Ruby Array none?()用法及代码示例
- Ruby Array pop()用法及代码示例
- Ruby Array zip()用法及代码示例
- Ruby Array one?()用法及代码示例
- Ruby Array map()用法及代码示例
- Ruby Array min()用法及代码示例
- Scala Array &()用法及代码示例
- Ruby Array max()用法及代码示例
- Ruby Array shift()用法及代码示例
- Ruby Array uniq!()用法及代码示例
- Ruby Array transpose()用法及代码示例
注:本文由纯净天空筛选整理自mayank5326大神的英文原创作品 Ruby | Array abbrev() function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。