summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-25 13:34:27 +0000
committerzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-25 13:34:27 +0000
commitd3908b7f83b6beac794e4fdbfc29b430ceed524c (patch)
treeb9739e6534f5d4759a28c3dfb7bb3dcca75c55d2 /lib
parent4398093755824d8aa24095e97c70c5b700989362 (diff)
* 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
Diffstat (limited to 'lib')
-rwxr-xr-xlib/abbrev.rb84
1 files changed, 45 insertions, 39 deletions
diff --git a/lib/abbrev.rb b/lib/abbrev.rb
index 841f6d980e..f8c518ca89 100755
--- a/lib/abbrev.rb
+++ b/lib/abbrev.rb
@@ -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 crab}, /b/)
+ # #=> {"box"=>"box", "bo"=>"box", "b"=>"box", "crab" => "crab"}
#
- # Abbrev.abbrev(%w{car box cone}, /b/)
- # #=> {"bo"=>"box", "b"=>"box", "box"=>"box"}
+ # 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)