зеркало из https://github.com/github/ruby.git
RDoc abbrev
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
f8c7b41165
Коммит
e10e26d329
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче