diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-02 00:32:30 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-02 00:32:30 +0000 |
commit | cc2a16d94d744d14d4a5eb06eca22137f8a9b79e (patch) | |
tree | 2907a20e2d9ae3a2831707056bb3fe2d384b066d /lib/rdoc/ri | |
parent | 918f625a5eeba35b9b191cb39c1d634b4cc7efee (diff) | |
download | ruby-cc2a16d94d744d14d4a5eb06eca22137f8a9b79e.tar.gz |
Import RDoc 3.5.1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/ri')
-rw-r--r-- | lib/rdoc/ri/driver.rb | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb index 112d65399c..9a336f7f3f 100644 --- a/lib/rdoc/ri/driver.rb +++ b/lib/rdoc/ri/driver.rb @@ -651,12 +651,14 @@ Options may also be set in the 'RI' environment variable. raise NotFoundError, name if found.empty? + filtered = filter_methods found, name + out = RDoc::Markup::Document.new out << RDoc::Markup::Heading.new(1, name) out << RDoc::Markup::BlankLine.new - found.each do |store, methods| + filtered.each do |store, methods| methods.each do |method| out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})") @@ -754,6 +756,21 @@ Options may also be set in the 'RI' environment variable. end ## + # Filters the methods in +found+ trying to find a match for +name+. + + def filter_methods found, name + regexp = name_regexp name + + filtered = found.find_all do |store, methods| + methods.any? { |method| method.full_name =~ regexp } + end + + return filtered unless filtered.empty? + + found + end + + ## # Yields items matching +name+ including the store they were found in, the # class being searched for, the class they were found in (an ancestor) the # types of methods to look up (from #method_type), and the method name being @@ -948,10 +965,10 @@ Options may also be set in the 'RI' environment variable. methods = [] methods << load_method(store, :class_methods, ancestor, '::', method) if - types == :class or types == :both + [:class, :both].include? types methods << load_method(store, :instance_methods, ancestor, '#', method) if - types == :instance or types == :both + [:instance, :both].include? types found << [store, methods.compact] end @@ -971,6 +988,21 @@ Options may also be set in the 'RI' environment variable. end ## + # Returns a regular expression for +name+ that will match an + # RDoc::AnyMethod's name. + + def name_regexp name + klass, type, name = parse_name name + + case type + when '#', '::' then + /^#{klass}#{type}#{name}$/ + else + /^#{klass}(#|::)#{name}$/ + end + end + + ## # Paginates output through a pager program. def page @@ -996,7 +1028,7 @@ Options may also be set in the 'RI' environment variable. end ## - # Extract the class, selector and method name parts from +name+ like + # Extracts the class, selector and method name parts from +name+ like # Foo::Bar#baz. # # NOTE: Given Foo::Bar, Bar is considered a class even though it may be a |