[前][次][番号順一覧][スレッド一覧]

ruby-changes:3866

From: ko1@a...
Date: Thu, 31 Jan 2008 14:11:12 +0900 (JST)
Subject: [ruby-changes:3866] usa - Ruby:r15355 (trunk): * lib/rdoc/ri/display.rb (display_method_list, display_class_list):

usa	2008-01-31 14:10:58 +0900 (Thu, 31 Jan 2008)

  New Revision: 15355

  Modified files:
    trunk/ChangeLog
    trunk/lib/rdoc/ri/display.rb
    trunk/lib/rdoc/ri/driver.rb

  Log:
    * lib/rdoc/ri/display.rb (display_method_list, display_class_list):
      use @formatter.raw_print_line instead of puts.
    
    * lib/rdoc/ri/driver.rb (select_methods): new method to collect all
      instance/class methods which match with passed pattern.
    
    * lib/rdoc/ri/driver.rb (run): use class_cache's result directly
      instead of select_classes' because it's removed now.
    
    * lib/rdoc/ri/driver.rb (run): search methods when passed name is not
      class name. [ruby-core:15309]
    


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/ri/driver.rb?r1=15355&r2=15354&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15355&r2=15354&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/ri/display.rb?r1=15355&r2=15354&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15354)
+++ ChangeLog	(revision 15355)
@@ -1,3 +1,17 @@
+Thu Jan 31 14:03:38 2008  NAKAMURA Usaku  <usa@r...>
+
+	* lib/rdoc/ri/display.rb (display_method_list, display_class_list):
+	  use @formatter.raw_print_line instead of puts.
+
+	* lib/rdoc/ri/driver.rb (select_methods): new method to collect all
+	  instance/class methods which match with passed pattern.
+
+	* lib/rdoc/ri/driver.rb (run): use class_cache's result directly
+	  instead of select_classes' because it's removed now.
+
+	* lib/rdoc/ri/driver.rb (run): search methods when passed name is not
+	  class name. [ruby-core:15309]
+
 Thu Jan 31 08:31:19 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* common.mk (ext/extmk.rb, instruby.rb): inlined $(MAKE) so that can
Index: lib/rdoc/ri/display.rb
===================================================================
--- lib/rdoc/ri/display.rb	(revision 15354)
+++ lib/rdoc/ri/display.rb	(revision 15355)
@@ -136,16 +136,16 @@
 
   def display_method_list(methods)
     page do
-      puts "More than one method matched your request. You can refine"
-      puts "your search by asking for information on one of:\n\n"
+      @formatter.raw_print_line("More than one method matched your request. You can refine")
+      @formatter.raw_print_line("your search by asking for information on one of:\n\n")
       @formatter.wrap(methods.map {|m| m.full_name} .join(", "))
     end
   end
 
   def display_class_list(namespaces)
     page do
-      puts "More than one class or module matched your request. You can refine"
-      puts "your search by asking for information on one of:\n\n"
+      @formatter.raw_print_line("More than one class or module matched your request. You can refine")
+      @formatter.raw_print_line("your search by asking for information on one of:\n\n")
       @formatter.wrap(namespaces.map {|m| m.full_name}.join(", "))
     end
   end
Index: lib/rdoc/ri/driver.rb
===================================================================
--- lib/rdoc/ri/driver.rb	(revision 15354)
+++ lib/rdoc/ri/driver.rb	(revision 15355)
@@ -346,7 +346,7 @@
 
   def run
     if @names.empty? then
-      @display.list_known_classes select_classes
+      @display.list_known_classes class_cache.keys.sort
     else
       @names.each do |name|
         case name
@@ -371,17 +371,33 @@
           if class_cache.key? name then
             display_class name
           else
-            @display.list_known_classes select_classes(/^#{name}/)
+            methods = select_methods(/^#{name}/)
+            if methods.size == 0
+              abort "Nothing known about #{name}"
+            elsif methods.size == 1
+              @display.display_method_info methods.first
+            else
+              @display.display_method_list methods
+            end
           end
         end
       end
     end
   end
 
-  def select_classes(pattern = nil)
-    classes = class_cache.keys.sort
-    classes = classes.grep pattern if pattern
-    classes
+  def select_methods(pattern)
+    methods = []
+    class_cache.keys.sort.each do |klass|
+      class_cache[klass]["instance_methods"].map{|h|h["name"]}.grep(pattern) do |name|
+        method = load_cache_for(klass)[klass+'#'+name]
+        methods << method if method
+      end
+      class_cache[klass]["class_methods"].map{|h|h["name"]}.grep(pattern) do |name|
+        method = load_cache_for(klass)[klass+'::'+name]
+        methods << method if method
+      end
+    end
+    methods
   end
 
   def write_cache(cache, path)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]