summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-20 05:27:23 +0000
committerdave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-20 05:27:23 +0000
commit6bdd34522a5b33c063119f37fdd0713f166176d1 (patch)
tree943e02f93534e0f900fb7ba1742ad413f45c3408
parentbe44c886d45db39a2f42fcec78f4a0cc67230f22 (diff)
RDoc abbrev
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@5513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--lib/abbrev.rb38
2 files changed, 42 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ccf1d71658..398183915c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Jan 20 14:25:51 2004 Dave Thomas <dave@pragprog.com>
+
+ * lib/abbrev.rb: Add RDoc
+
Tue Jan 20 13:22:39 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/html_generator.rb: Document aliases at
diff --git a/lib/abbrev.rb b/lib/abbrev.rb
index 9cd3a71e40..6530679681 100644
--- a/lib/abbrev.rb
+++ b/lib/abbrev.rb
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
+=begin
#
# Copyright (c) 2001,2003 Akinori MUSHA <knu@iDaemons.org>
#
@@ -8,8 +9,38 @@
# $Idaemons: /home/cvs/rb/abbrev.rb,v 1.2 2001/05/30 09:37:45 knu Exp $
# $RoughId: abbrev.rb,v 1.4 2003/10/14 19:45:42 knu Exp $
# $Id$
+=end
+
+# Calculate the set of unique abbreviations for a given set of strings.
+#
+# require 'abbrev'
+# require 'pp'
+#
+# pp Abbrev::abbrev(['ruby', 'rules']).sort
+#
+# <i>Generates:</i>
+#
+# [["rub", "ruby"],
+# ["ruby", "ruby"],
+# ["rul", "rules"],
+# ["rule", "rules"],
+# ["rules", "rules"]]
+#
+# Also adds an +abbrev+ method to class +Array+.
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. Thus, given input of "car" and "cone", the keys pointing
+ # to "car" would be "ca" and "car", while those pointing to "cone"
+ # would be "co", "con", and "cone".
+ #
+ # The optional +pattern+ parameter is a pattern or a string. Only
+ # those input strings matching the pattern, or begging the string,
+ # are considered for inclusion in the output hash
+
def abbrev(words, pattern = nil)
table = {}
seen = Hash.new(0)
@@ -49,6 +80,13 @@ module Abbrev
end
class Array
+ # Calculates the set of unambiguous abbreviations for the strings in
+ # +self+. If passed a pattern or a string, only the strings matching
+ # the pattern or starting with the string are considered.
+ #
+ # %w{ car cone }.abbrev #=> { "ca" => "car", "car" => "car",
+ # "co" => "cone", "con" => cone",
+ # "cone" => "cone" }
def abbrev(pattern = nil)
Abbrev::abbrev(self, pattern)
end