ruby-changes:25061
From: zzak <ko1@a...>
Date: Sun, 7 Oct 2012 05:03:40 +0900 (JST)
Subject: [ruby-changes:25061] zzak:r37113 (trunk): * lib/abbrev.rb: Documentation examples for Abbrev.
zzak 2012-10-07 05:03:26 +0900 (Sun, 07 Oct 2012) New Revision: 37113 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37113 Log: * lib/abbrev.rb: Documentation examples for Abbrev. [ruby-dev:47442] [Bug #6985] Modified files: trunk/ChangeLog trunk/lib/abbrev.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 37112) +++ ChangeLog (revision 37113) @@ -1,5 +1,10 @@ Sun Oct 7 04:50:00 2012 Zachary Scott <zzak@r...> + * lib/abbrev.rb: Documentation examples for Abbrev. + [ruby-dev:47442] [Bug #6985] + +Sun Oct 7 04:50:00 2012 Zachary Scott <zzak@r...> + * thread.c (rb_thread_aref): Grammar in Thread documentation. Patch by Steve Klabnik [ruby-dev:47799] [Bug #7099] Index: lib/abbrev.rb =================================================================== --- lib/abbrev.rb (revision 37112) +++ lib/abbrev.rb (revision 37113) @@ -26,21 +26,45 @@ # "rule" => "rules", # "rules" => "rules" } # -# It also adds an +abbrev+ method to class Array. +# It also provides an array core extension, Array#abbrev. +# +# pp %w{april may}.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"} 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". + # 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". + # + # require 'abbrev' + # require 'pp' + # + # pp Abbrev.abbrev(['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. - + # + # pp %w{car box cone}.abbrev(/b/) + # #=> {"bo"=>"box", "b"=>"box", "box"=>"box"} def abbrev(words, pattern = nil) table = {} seen = Hash.new(0) @@ -83,15 +107,20 @@ # Calculates the set of unambiguous abbreviations for the strings in # +self+. # + # abbr = %w{ car cone }.abbrev + # abbr #=> { "ca" => "car", "car" => "car", + # "co" => "cone", "con" => "cone", + # "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. # - # %w{ car cone }.abbrev #=> { "ca" => "car", "car" => "car", - # "co" => "cone", "con" => "cone", - # "cone" => "cone" } + # abbr = %w{ fast boat day }.abbrev(/^.a.*$/) + # abbr #=> {"fas"=>"fast","fa"=>"fast", + # "da"=>"day", "fast"=>"fast", "day"=>"day"} # - # See also Abbrev#abbrev + # See also Abbrev.abbrev def abbrev(pattern = nil) Abbrev::abbrev(self, pattern) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/