1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/abbrev.rb: [DOC] rdoc format patch by Giorgos Tsiftsis [Bug #9146]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
zzak 2013-12-25 13:34:27 +00:00
parent 4398093755
commit d3908b7f83
2 changed files with 49 additions and 39 deletions

View file

@ -1,3 +1,7 @@
Wed Dec 25 22:32:19 2013 Zachary Scott <e@zzak.io>
* lib/abbrev.rb: [DOC] rdoc format patch by Giorgos Tsiftsis [Bug #9146]
Wed Dec 25 20:30:10 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* iseq.c (rb_iseq_parameters): push argument type symbol only for

View file

@ -11,43 +11,46 @@
#++
##
# Calculates the set of unique abbreviations for a given set of strings.
# Calculates the set of unambiguous abbreviations for a given set of strings.
#
# require 'abbrev'
# require 'pp'
#
# pp Abbrev.abbrev(['ruby', 'rules'])
# pp Abbrev.abbrev(['ruby'])
# #=> {"ruby"=>"ruby", "rub"=>"ruby", "ru"=>"ruby", "r"=>"ruby"}
#
# Generates:
# pp Abbrev.abbrev(%w{ ruby rules })
#
# { "rub" => "ruby",
# "ruby" => "ruby",
# "rul" => "rules",
# _Generates:_
# { "ruby" => "ruby",
# "rub" => "ruby",
# "rules" => "rules",
# "rule" => "rules",
# "rules" => "rules" }
# "rul" => "rules" }
#
# It also provides an array core extension, 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"}
# 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" }
module Abbrev
# 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.
# 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
@ -55,15 +58,18 @@ module Abbrev
#
# require 'abbrev'
#
# Abbrev.abbrev(['car', 'cone'])
# Abbrev.abbrev(%w{ 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.
# 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"}
# Abbrev.abbrev(%w{car box cone crab}, /b/)
# #=> {"box"=>"box", "bo"=>"box", "b"=>"box", "crab" => "crab"}
#
# Abbrev.abbrev(%w{car box cone}, 'ca')
# #=> {"car"=>"car", "ca"=>"car"}
def abbrev(words, pattern = nil)
table = {}
seen = Hash.new(0)
@ -103,21 +109,21 @@ module Abbrev
end
class Array
# Calculates the set of unambiguous abbreviations for the strings in
# +self+.
# Calculates the set of unambiguous abbreviations for the strings in +self+.
#
# require 'abbrev'
# %w{ car cone }.abbrev
# #=> {"ca" => "car", "con"=>"cone", "co" => "cone",
# "car"=>"car", "cone" => "cone"}
# #=> {"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.
# 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.
#
# %w{ fast boat day }.abbrev(/^.a/)
# #=> {"fas"=>"fast", "fa"=>"fast", "da"=>"day",
# "fast"=>"fast", "day"=>"day"}
# #=> {"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
def abbrev(pattern = nil)