@@ -335,13 +335,13 @@ def load_cache_for(klassname)
335335
336336 if File . exist? path and
337337 File . mtime ( path ) >= File . mtime ( class_cache_file_path ) then
338- File . open path , 'rb' do |fp |
338+ open path , 'rb' do |fp |
339339 cache = Marshal . load fp . read
340340 end
341341 else
342342 class_cache = nil
343343
344- File . open class_cache_file_path , 'rb' do |fp |
344+ open class_cache_file_path , 'rb' do |fp |
345345 class_cache = Marshal . load fp . read
346346 end
347347
@@ -372,17 +372,34 @@ def load_cache_for(klassname)
372372 RDoc ::RI ::Driver ::Hash . convert cache
373373 end
374374
375+ ##
376+ # Finds the next ancestor of +orig_klass+ after +klass+.
377+
378+ def lookup_ancestor ( klass , orig_klass , ancestor = nil )
379+ cache = class_cache [ orig_klass ]
380+
381+ return nil unless cache
382+
383+ ancestors ||= [ orig_klass ]
384+ ancestors . push ( *cache . includes . map { |inc | inc [ 'name' ] } )
385+ ancestors << cache . superclass
386+
387+ ancestor = ancestors [ ancestors . index ( klass ) + 1 ]
388+
389+ return ancestor if ancestor
390+
391+ lookup_ancestor klass , cache . superclass
392+ end
393+
375394 ##
376395 # Finds the method
377396
378397 def lookup_method ( name , klass )
379398 cache = load_cache_for klass
380- raise NotFoundError , name unless cache
399+ return nil unless cache
381400
382401 method = cache [ name . gsub ( '.' , '#' ) ]
383402 method = cache [ name . gsub ( '.' , '::' ) ] unless method
384- raise NotFoundError , name unless method
385-
386403 method
387404 end
388405
@@ -459,11 +476,25 @@ def run
459476 if class_cache . key? name then
460477 display_class name
461478 else
462- meth = nil
479+ klass , = parse_name name
480+
481+ orig_klass = klass
482+ orig_name = name
483+
484+ until klass == 'Kernel' do
485+ method = lookup_method name , klass
486+
487+ break method if method
463488
464- klass , meth = parse_name name
489+ ancestor = lookup_ancestor klass , orig_klass
465490
466- method = lookup_method name , klass
491+ break unless ancestor
492+
493+ name = name . sub klass , ancestor
494+ klass = ancestor
495+ end
496+
497+ raise NotFoundError , orig_name unless method
467498
468499 @display . display_method_info method
469500 end
@@ -472,6 +503,7 @@ def run
472503 display_class name
473504 else
474505 methods = select_methods ( /^#{ name } / )
506+
475507 if methods . size == 0
476508 raise NotFoundError , name
477509 elsif methods . size == 1
0 commit comments