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:
parent
4398093755
commit
d3908b7f83
2 changed files with 49 additions and 39 deletions
|
@ -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>
|
Wed Dec 25 20:30:10 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* iseq.c (rb_iseq_parameters): push argument type symbol only for
|
* iseq.c (rb_iseq_parameters): push argument type symbol only for
|
||||||
|
|
|
@ -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 'abbrev'
|
||||||
# require 'pp'
|
# 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",
|
# _Generates:_
|
||||||
# "ruby" => "ruby",
|
# { "ruby" => "ruby",
|
||||||
# "rul" => "rules",
|
# "rub" => "ruby",
|
||||||
|
# "rules" => "rules",
|
||||||
# "rule" => "rules",
|
# "rule" => "rules",
|
||||||
# "rules" => "rules" }
|
# "rul" => "rules" }
|
||||||
#
|
#
|
||||||
# It also provides an array core extension, Array#abbrev.
|
# It also provides an array core extension, Array#abbrev.
|
||||||
#
|
#
|
||||||
# pp %w{summer winter}.abbrev
|
# pp %w{ summer winter }.abbrev
|
||||||
# #=> {"summe"=>"summer",
|
#
|
||||||
# "summ"=>"summer",
|
# _Generates:_
|
||||||
# "sum"=>"summer",
|
# { "summer" => "summer",
|
||||||
# "su"=>"summer",
|
# "summe" => "summer",
|
||||||
# "s"=>"summer",
|
# "summ" => "summer",
|
||||||
# "winte"=>"winter",
|
# "sum" => "summer",
|
||||||
# "wint"=>"winter",
|
# "su" => "summer",
|
||||||
# "win"=>"winter",
|
# "s" => "summer",
|
||||||
# "wi"=>"winter",
|
# "winter" => "winter",
|
||||||
# "w"=>"winter",
|
# "winte" => "winter",
|
||||||
# "summer"=>"summer",
|
# "wint" => "winter",
|
||||||
# "winter"=>"winter"}
|
# "win" => "winter",
|
||||||
|
# "wi" => "winter",
|
||||||
|
# "w" => "winter" }
|
||||||
|
|
||||||
module Abbrev
|
module Abbrev
|
||||||
|
|
||||||
# Given a set of strings, calculate the set of unambiguous
|
# Given a set of strings, calculate the set of unambiguous abbreviations for
|
||||||
# abbreviations for those strings, and return a hash where the keys
|
# those strings, and return a hash where the keys are all the possible
|
||||||
# are all the possible abbreviations and the values are the full
|
# abbreviations and the values are the full strings.
|
||||||
# strings.
|
|
||||||
#
|
#
|
||||||
# Thus, given +words+ is "car" and "cone", the keys pointing to "car" would
|
# 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
|
# be "ca" and "car", while those pointing to "cone" would be "co", "con", and
|
||||||
|
@ -55,15 +58,18 @@ module Abbrev
|
||||||
#
|
#
|
||||||
# require 'abbrev'
|
# require 'abbrev'
|
||||||
#
|
#
|
||||||
# Abbrev.abbrev(['car', 'cone'])
|
# Abbrev.abbrev(%w{ car cone })
|
||||||
# #=> {"ca"=>"car", "con"=>"cone", "co"=>"cone", "car"=>"car", "cone"=>"cone"}
|
# #=> {"ca"=>"car", "con"=>"cone", "co"=>"cone", "car"=>"car", "cone"=>"cone"}
|
||||||
#
|
#
|
||||||
# The optional +pattern+ parameter is a pattern or a string. Only
|
# The optional +pattern+ parameter is a pattern or a string. Only input
|
||||||
# input strings that match the pattern or start with the string
|
# strings that match the pattern or start with the string are included in the
|
||||||
# are included in the output hash.
|
# output hash.
|
||||||
#
|
#
|
||||||
# Abbrev.abbrev(%w{car box cone}, /b/)
|
# Abbrev.abbrev(%w{car box cone crab}, /b/)
|
||||||
# #=> {"bo"=>"box", "b"=>"box", "box"=>"box"}
|
# #=> {"box"=>"box", "bo"=>"box", "b"=>"box", "crab" => "crab"}
|
||||||
|
#
|
||||||
|
# Abbrev.abbrev(%w{car box cone}, 'ca')
|
||||||
|
# #=> {"car"=>"car", "ca"=>"car"}
|
||||||
def abbrev(words, pattern = nil)
|
def abbrev(words, pattern = nil)
|
||||||
table = {}
|
table = {}
|
||||||
seen = Hash.new(0)
|
seen = Hash.new(0)
|
||||||
|
@ -103,21 +109,21 @@ module Abbrev
|
||||||
end
|
end
|
||||||
|
|
||||||
class Array
|
class Array
|
||||||
# Calculates the set of unambiguous abbreviations for the strings in
|
# Calculates the set of unambiguous abbreviations for the strings in +self+.
|
||||||
# +self+.
|
|
||||||
#
|
#
|
||||||
# require 'abbrev'
|
# require 'abbrev'
|
||||||
# %w{ car cone }.abbrev
|
# %w{ car cone }.abbrev
|
||||||
# #=> {"ca" => "car", "con"=>"cone", "co" => "cone",
|
# #=> {"car"=>"car", "ca"=>"car", "cone"=>"cone", "con"=>"cone", "co"=>"cone"}
|
||||||
# "car"=>"car", "cone" => "cone"}
|
|
||||||
#
|
#
|
||||||
# The optional +pattern+ parameter is a pattern or a string. Only
|
# The optional +pattern+ parameter is a pattern or a string. Only input
|
||||||
# input strings that match the pattern or start with the string
|
# strings that match the pattern or start with the string are included in the
|
||||||
# are included in the output hash.
|
# output hash.
|
||||||
#
|
#
|
||||||
# %w{ fast boat day }.abbrev(/^.a/)
|
# %w{ fast boat day }.abbrev(/^.a/)
|
||||||
# #=> {"fas"=>"fast", "fa"=>"fast", "da"=>"day",
|
# #=> {"fast"=>"fast", "fas"=>"fast", "fa"=>"fast", "day"=>"day", "da"=>"day"}
|
||||||
# "fast"=>"fast", "day"=>"day"}
|
#
|
||||||
|
# Abbrev.abbrev(%w{car box cone}, "ca")
|
||||||
|
# #=> {"car"=>"car", "ca"=>"car"}
|
||||||
#
|
#
|
||||||
# See also Abbrev.abbrev
|
# See also Abbrev.abbrev
|
||||||
def abbrev(pattern = nil)
|
def abbrev(pattern = nil)
|
||||||
|
|
Loading…
Reference in a new issue