On Thu, 21 Jun 2001, ts wrote:

> >>>>> "R" == Robert Feldt <feldt / ce.chalmers.se> writes:
> 
> R>   def cjust(width)
> 
>  This ?
> 
> pigeon% ruby -e 'p "abc".center(12)'
> "    abc     "
> pigeon% 
> 
You see, already too many features/methods for my little brain... ;-)

To remind me not to forget studying pickaxe book and ri output more
thoroughly in the future (before mailing to ruby-talk!) I patched ri so
that

$ ri Str#cen
The method named `cen' is not unique among Ruby's classes and modules:
     String#center

now outputs

$ ri Str#cen
---------------------------------------------------------- String#center
     str.center( anInteger ) -> aString
------------------------------------------------------------------------
     If anInteger is greater than the length of str, returns a new
     String of length anInteger with str centered between spaces;
     otherwise, returns str.
        "hello".center(4)    #=> "hello"
        "hello".center(20)   #=> "       hello        "

The diff is below. 
(Dave: Check out for other bugs I might have introduced though...)

Thanks and regards,

Robert

--- ri.rb.old	Thu Jun 21 10:26:17 2001
+++ ri.rb	Thu Jun 21 10:26:24 2001
@@ -222,12 +222,18 @@
     for cname in classList
       cl = findClass(cname)
       meths = cl.findMethods(mname, type == "::")
-      meths.each {|m| res <<
"#{cname}#{m.type=='class'?'::':'#'}#{m.name}" }
+      meths.each {|m| res << [cl, m, cname, m.type, m.name]}
     end
     
-    @op.putListOfMethodsMatchingName(mname) do
-      @op.putMethodList(res)
+    if res.length == 1
+      return res.first[0..1]
+    elsif res.length > 1
+      @op.putListOfMethodsMatchingName(mname) do
+	res.map! {|e| "#{e[2]}#{e[3]=='class'?'::':'#'}#{e[4]}" }
+	@op.putMethodList(res)
+      end
     end
+    return nil
   end
   
   
@@ -244,8 +250,9 @@
     
     case cl
     when Array
-      matchMethodsInClasses(cl, type, mname)
-      
+      res = matchMethodsInClasses(cl, type, mname)
+      reportMethod(res[0], res[1]) if res
+
     when ClassModule
       meths = cl.findMethods(mname, type == "::")
       
@@ -256,11 +263,7 @@
         throw :exit, 3
         
       when 1
-        meth = meths[0]
-        @op.putMethodDescription do
-          @op.putMethodHeader(cl.name, meth.typeAsSeparator, meth.name,
meth.callseq)
-          printFragments(meth) unless @synopsis
-        end
+        reportMethod(cl, meths.first)
         
       else
         @op.putListOfMethodsMatchingName(cl.name + type + mname) do
@@ -269,6 +272,16 @@
                             })
         end
       end
+    end
+  end
+
+  ##
+  # Report on method
+  #
+  def reportMethod(cl, meth)
+    @op.putMethodDescription do
+      @op.putMethodHeader(cl.name, meth.typeAsSeparator, meth.name,
meth.callseq)
+      printFragments(meth) unless @synopsis
     end
   end