Parent

RDoc::RI::Driver

The RI driver implements the command-line ri tool.

The driver supports:

Attributes

stores[RW]
use_stdout[RW]

Controls the user of the pager vs $stdout

Public Class Methods

default_options() click to toggle source

Default options for ri

    # File lib/rdoc/ri/driver.rb, line 68
68:   def self.default_options
69:     options = {}
70:     options[:use_stdout] = !$stdout.tty?
71:     options[:width] = 72
72:     options[:interactive] = false
73:     options[:use_cache] = true
74:     options[:profile] = false
75: 
76:     # By default all standard paths are used.
77:     options[:use_system] = true
78:     options[:use_site] = true
79:     options[:use_home] = true
80:     options[:use_gems] = true
81:     options[:extra_doc_dirs] = []
82: 
83:     return options
84:   end
dump(data_path) click to toggle source

Dump data_path using pp

    # File lib/rdoc/ri/driver.rb, line 89
89:   def self.dump data_path
90:     require 'pp'
91: 
92:     open data_path, 'rb' do |io|
93:       pp Marshal.load(io.read)
94:     end
95:   end
new(initial_options = {}) click to toggle source

Creates a new driver using initial_options from ::process_args

     # File lib/rdoc/ri/driver.rb, line 315
315:   def initialize initial_options = {}
316:     @paging = false
317:     @classes = nil
318: 
319:     options = self.class.default_options.update(initial_options)
320: 
321:     @formatter_klass = options[:formatter]
322: 
323:     require 'profile' if options[:profile]
324: 
325:     @names = options[:names]
326: 
327:     @doc_dirs = []
328:     @stores   = []
329: 
330:     RDoc::RI::Paths.each(options[:use_system], options[:use_site],
331:                                    options[:use_home], options[:use_gems],
332:                                    *options[:extra_doc_dirs]) do |path, type|
333:       @doc_dirs << path
334: 
335:       store = RDoc::RI::Store.new path, type
336:       store.load_cache
337:       @stores << store
338:     end
339: 
340:     @list_doc_dirs = options[:list_doc_dirs]
341: 
342:     @interactive = options[:interactive]
343:     @use_stdout  = options[:use_stdout]
344:   end
process_args(argv) click to toggle source

Parses argv and returns a Hash of options

     # File lib/rdoc/ri/driver.rb, line 100
100:   def self.process_args argv
101:     options = default_options
102: 
103:     opts = OptionParser.new do |opt|
104:       opt.accept File do |file,|
105:         File.readable?(file) and not File.directory?(file) and file
106:       end
107: 
108:       opt.program_name = File.basename $0
109:       opt.version = RDoc::VERSION
110:       opt.release = nil
111:       opt.summary_indent = ' ' * 4
112: 
113:       opt.banner = Usage: #{opt.program_name} [options] [names...]Where name can be:  Class | Class::method | Class#method | Class.method | methodAll class names may be abbreviated to their minimum unambiguous form. If a nameis ambiguous, all valid options will be listed.The form '.' method matches either class or instance methods, while #methodmatches only instance and ::method matches only class methods.For example:    #{opt.program_name} Fil    #{opt.program_name} File    #{opt.program_name} File.new    #{opt.program_name} zipNote that shell quoting may be required for method names containingpunctuation:    #{opt.program_name} 'Array.[]'    #{opt.program_name} compact\\!To see the default directories ri will search, run:    #{opt.program_name} --list-doc-dirsSpecifying the --system, --site, --home, --gems or --doc-dir options willlimit ri to searching only the specified directories.Options may also be set in the 'RI' environment variable.
114: 
115:       opt.separator nil
116:       opt.separator "Options:"
117: 
118:       opt.separator nil
119: 
120:       formatters = RDoc::Markup.constants.grep(/^To[A-Z][a-z]+$/).sort
121:       formatters = formatters.sort.map do |formatter|
122:         formatter.to_s.sub('To', '').downcase
123:       end
124: 
125:       opt.on("--format=NAME", "-f",
126:              "Uses the selected formatter. The default",
127:              "formatter is bs for paged output and ansi",
128:              "otherwise. Valid formatters are:",
129:              formatters.join(' '), formatters) do |value|
130:         options[:formatter] = RDoc::Markup.const_get "To#{value.capitalize}"
131:       end
132: 
133:       opt.separator nil
134: 
135:       opt.on("--no-pager", "-T",
136:              "Send output directly to stdout,",
137:              "rather than to a pager.") do
138:         options[:use_stdout] = true
139:       end
140: 
141:       opt.separator nil
142: 
143:       opt.on("--width=WIDTH", "-w", OptionParser::DecimalInteger,
144:              "Set the width of the output.") do |value|
145:         options[:width] = value
146:       end
147: 
148:       opt.separator nil
149: 
150:       opt.on("--interactive", "-i",
151:              "In interactive mode you can repeatedly",
152:              "look up methods with autocomplete.") do
153:         options[:interactive] = true
154:       end
155: 
156:       opt.separator nil
157: 
158:       opt.on("--[no-]profile",
159:              "Run with the ruby profiler") do |value|
160:         options[:profile] = value
161:       end
162: 
163:       opt.separator nil
164:       opt.separator "Data source options:"
165:       opt.separator nil
166: 
167:       opt.on("--list-doc-dirs",
168:              "List the directories from which ri will",
169:              "source documentation on stdout and exit.") do
170:         options[:list_doc_dirs] = true
171:       end
172: 
173:       opt.separator nil
174: 
175:       opt.on("--doc-dir=DIRNAME", "-d", Array,
176:              "List of directories from which to source",
177:              "documentation in addition to the standard",
178:              "directories.  May be repeated.") do |value|
179:         value.each do |dir|
180:           unless File.directory? dir then
181:             raise OptionParser::InvalidArgument, "#{dir} is not a directory"
182:           end
183: 
184:           options[:extra_doc_dirs] << File.expand_path(dir)
185:         end
186:       end
187: 
188:       opt.separator nil
189: 
190:       opt.on("--no-standard-docs",
191:              "Do not include documentation from",
192:              "the Ruby standard library, site_lib,",
193:              "installed gems, or ~/.rdoc.",
194:              "Use with --doc-dir") do
195:         options[:use_system] = false
196:         options[:use_site] = false
197:         options[:use_gems] = false
198:         options[:use_home] = false
199:       end
200: 
201:       opt.separator nil
202: 
203:       opt.on("--[no-]system",
204:              "Include documentation from Ruby's standard",
205:              "library.  Defaults to true.") do |value|
206:         options[:use_system] = value
207:       end
208: 
209:       opt.separator nil
210: 
211:       opt.on("--[no-]site",
212:              "Include documentation from libraries",
213:              "installed in site_lib.",
214:              "Defaults to true.") do |value|
215:         options[:use_site] = value
216:       end
217: 
218:       opt.separator nil
219: 
220:       opt.on("--[no-]gems",
221:              "Include documentation from RubyGems.",
222:              "Defaults to true.") do |value|
223:         options[:use_gems] = value
224:       end
225: 
226:       opt.separator nil
227: 
228:       opt.on("--[no-]home",
229:              "Include documentation stored in ~/.rdoc.",
230:              "Defaults to true.") do |value|
231:         options[:use_home] = value
232:       end
233: 
234:       opt.separator nil
235:       opt.separator "Debug options:"
236:       opt.separator nil
237: 
238:       opt.on("--dump=CACHE", File,
239:              "Dumps data from an ri cache or data file") do |value|
240:         options[:dump_path] = value
241:       end
242:     end
243: 
244:     argv = ENV['RI'].to_s.split.concat argv
245: 
246:     opts.parse! argv
247: 
248:     options[:names] = argv
249: 
250:     options[:use_stdout] ||= !$stdout.tty?
251:     options[:use_stdout] ||= options[:interactive]
252:     options[:width] ||= 72
253: 
254:     options
255: 
256:   rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
257:     puts opts
258:     puts
259:     puts e
260:     exit 1
261:   end
run(argv = ARGV) click to toggle source

Runs the ri command line executable using argv

     # File lib/rdoc/ri/driver.rb, line 300
300:   def self.run argv = ARGV
301:     options = process_args argv
302: 
303:     if options[:dump_path] then
304:       dump options[:dump_path]
305:       return
306:     end
307: 
308:     ri = new options
309:     ri.run
310:   end

Public Instance Methods

add_also_in(out, also_in) click to toggle source

Adds paths for undocumented classes also_in to out

     # File lib/rdoc/ri/driver.rb, line 349
349:   def add_also_in out, also_in
350:     return if also_in.empty?
351: 
352:     out << RDoc::Markup::Rule.new(1)
353:     out << RDoc::Markup::Paragraph.new("Also found in:")
354: 
355:     paths = RDoc::Markup::Verbatim.new
356:     also_in.each do |store|
357:       paths.parts.push '  ', store.friendly_path, "\n"
358:     end
359:     out << paths
360:   end
add_class(out, name, classes) click to toggle source

Adds a class header to out for class name which is described in classes.

     # File lib/rdoc/ri/driver.rb, line 366
366:   def add_class out, name, classes
367:     heading = if classes.all? { |klass| klass.module? } then
368:                 name
369:               else
370:                 superclass = classes.map do |klass|
371:                   klass.superclass unless klass.module?
372:                 end.compact.shift || 'Object'
373: 
374:                 "#{name} < #{superclass}"
375:               end
376: 
377:     out << RDoc::Markup::Heading.new(1, heading)
378:     out << RDoc::Markup::BlankLine.new
379:   end
add_from(out, store) click to toggle source

Adds “(from …)” to out for store

     # File lib/rdoc/ri/driver.rb, line 384
384:   def add_from out, store
385:     out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})")
386:   end
add_includes(out, includes) click to toggle source

Adds includes to out

     # File lib/rdoc/ri/driver.rb, line 391
391:   def add_includes out, includes
392:     return if includes.empty?
393: 
394:     out << RDoc::Markup::Rule.new(1)
395:     out << RDoc::Markup::Heading.new(1, "Includes:")
396: 
397:     includes.each do |modules, store|
398:       if modules.length == 1 then
399:         include = modules.first
400:         name = include.name
401:         path = store.friendly_path
402:         out << RDoc::Markup::Paragraph.new("#{name} (from #{path})")
403: 
404:         if include.comment then
405:           out << RDoc::Markup::BlankLine.new
406:           out << include.comment
407:         end
408:       else
409:         out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})")
410: 
411:         wout, with = modules.partition { |incl| incl.comment.empty? }
412: 
413:         out << RDoc::Markup::BlankLine.new unless with.empty?
414: 
415:         with.each do |incl|
416:           out << RDoc::Markup::Paragraph.new(incl.name)
417:           out << RDoc::Markup::BlankLine.new
418:           out << incl.comment
419:         end
420: 
421:         unless wout.empty? then
422:           verb = RDoc::Markup::Verbatim.new
423: 
424:           wout.each do |incl|
425:             verb.push '  ', incl.name, "\n"
426:           end
427: 
428:           out << verb
429:         end
430:       end
431:     end
432:   end
add_method_list(out, methods, name) click to toggle source

Adds a list of methods to out with a heading of name

     # File lib/rdoc/ri/driver.rb, line 437
437:   def add_method_list out, methods, name
438:     return unless methods
439: 
440:     out << RDoc::Markup::Heading.new(1, "#{name}:")
441:     out << RDoc::Markup::BlankLine.new
442: 
443:     out.push(*methods.map do |method|
444:       RDoc::Markup::Verbatim.new '  ', method
445:     end)
446: 
447:     out << RDoc::Markup::BlankLine.new
448:   end
ancestors_of(klass) click to toggle source

Returns ancestor classes of klass

     # File lib/rdoc/ri/driver.rb, line 453
453:   def ancestors_of klass
454:     ancestors = []
455: 
456:     unexamined = [klass]
457:     seen = []
458: 
459:     loop do
460:       break if unexamined.empty?
461:       current = unexamined.shift
462:       seen << current
463: 
464:       stores = classes[current]
465: 
466:       break unless stores and not stores.empty?
467: 
468:       klasses = stores.map do |store|
469:         store.ancestors[current]
470:       end.flatten.uniq
471: 
472:       klasses = klasses - seen
473: 
474:       ancestors.push(*klasses)
475:       unexamined.push(*klasses)
476:     end
477: 
478:     ancestors.reverse
479:   end
classes() click to toggle source

Hash mapping a known class or module to the stores it can be loaded from

     # File lib/rdoc/ri/driver.rb, line 490
490:   def classes
491:     return @classes if @classes
492: 
493:     @classes = {}
494: 
495:     @stores.each do |store|
496:       store.cache[:modules].each do |mod|
497:         # using default block causes searched-for modules to be added
498:         @classes[mod] ||= []
499:         @classes[mod] << store
500:       end
501:     end
502: 
503:     @classes
504:   end
complete(name) click to toggle source

Completes name based on the caches. For Readline

     # File lib/rdoc/ri/driver.rb, line 509
509:   def complete name
510:     klasses = classes.keys
511:     completions = []
512: 
513:     klass, selector, method = parse_name name
514: 
515:     # may need to include Foo when given Foo::
516:     klass_name = method ? name : klass
517: 
518:     if name !~ /#|\./ then
519:       completions.push(*klasses.grep(/^#{klass_name}/))
520:     elsif selector then
521:       completions << klass if classes.key? klass
522:     elsif classes.key? klass_name then
523:       completions << klass_name
524:     end
525: 
526:     if completions.include? klass and name =~ /#|\.|::/ then
527:       methods = list_methods_matching name
528: 
529:       if not methods.empty? then
530:         # remove Foo if given Foo:: and a method was found
531:         completions.delete klass
532:       elsif selector then
533:         # replace Foo with Foo:: as given
534:         completions.delete klass
535:         completions << "#{klass}#{selector}"
536:       end
537: 
538:       completions.push(*methods)
539:     end
540: 
541:     completions.sort
542:   end
display(document) click to toggle source

Converts document to text and writes it to the pager

     # File lib/rdoc/ri/driver.rb, line 547
547:   def display document
548:     page do |io|
549:       text = document.accept formatter
550: 
551:       io.write text
552:     end
553:   end
display_class(name) click to toggle source

Outputs formatted RI data for class name. Groups undocumented classes

     # File lib/rdoc/ri/driver.rb, line 558
558:   def display_class name
559:     return if name =~ /#|\./
560: 
561:     klasses = []
562:     includes = []
563: 
564:     found = @stores.map do |store|
565:       begin
566:         klass = store.load_class name
567:         klasses  << klass
568:         includes << [klass.includes, store] if klass.includes
569:         [store, klass]
570:       rescue Errno::ENOENT
571:       end
572:     end.compact
573: 
574:     return if found.empty?
575: 
576:     also_in = []
577: 
578:     includes.reject! do |modules,| modules.empty? end
579: 
580:     out = RDoc::Markup::Document.new
581: 
582:     add_class out, name, klasses
583: 
584:     add_includes out, includes
585: 
586:     found.each do |store, klass|
587:       comment = klass.comment
588:       class_methods    = store.class_methods[klass.full_name]
589:       instance_methods = store.instance_methods[klass.full_name]
590:       attributes       = store.attributes[klass.full_name]
591: 
592:       if comment.empty? and !(instance_methods or class_methods) then
593:         also_in << store
594:         next
595:       end
596: 
597:       add_from out, store
598: 
599:       unless comment.empty? then
600:         out << RDoc::Markup::Rule.new(1)
601:         out << comment
602:       end
603: 
604:       if class_methods or instance_methods or not klass.constants.empty? then
605:         out << RDoc::Markup::Rule.new
606:       end
607: 
608:       unless klass.constants.empty? then
609:         out << RDoc::Markup::Heading.new(1, "Constants:")
610:         out << RDoc::Markup::BlankLine.new
611:         list = RDoc::Markup::List.new :NOTE
612: 
613:         constants = klass.constants.sort_by { |constant| constant.name }
614: 
615:         list.push(*constants.map do |constant|
616:           parts = constant.comment.parts if constant.comment
617:           parts << RDoc::Markup::Paragraph.new('[not documented]') if
618:             parts.empty?
619: 
620:           RDoc::Markup::ListItem.new(constant.name, *parts)
621:         end)
622: 
623:         out << list
624:       end
625: 
626:       add_method_list out, class_methods,    'Class methods'
627:       add_method_list out, instance_methods, 'Instance methods'
628:       add_method_list out, attributes,       'Attributes'
629: 
630:       out << RDoc::Markup::BlankLine.new
631:     end
632: 
633:     add_also_in out, also_in
634: 
635:     display out
636:   end
display_method(name) click to toggle source

Outputs formatted RI data for method name

     # File lib/rdoc/ri/driver.rb, line 641
641:   def display_method name
642:     found = load_methods_matching name
643: 
644:     raise NotFoundError, name if found.empty?
645: 
646:     out = RDoc::Markup::Document.new
647: 
648:     out << RDoc::Markup::Heading.new(1, name)
649:     out << RDoc::Markup::BlankLine.new
650: 
651:     found.each do |store, methods|
652:       methods.each do |method|
653:         out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})")
654: 
655:         unless name =~ /^#{Regexp.escape method.parent_name}/ then
656:           out << RDoc::Markup::Heading.new(3, "Implementation from #{method.parent_name}")
657:         end
658:         out << RDoc::Markup::Rule.new(1)
659: 
660:         if method.arglists then
661:           arglists = method.arglists.chomp.split "\n"
662:           arglists = arglists.map { |line| ['  ', line, "\n"] }
663:           out << RDoc::Markup::Verbatim.new(*arglists.flatten)
664:           out << RDoc::Markup::Rule.new(1)
665:         end
666: 
667:         out << RDoc::Markup::BlankLine.new
668:         out << method.comment
669:         out << RDoc::Markup::BlankLine.new
670:       end
671:     end
672: 
673:     display out
674:   end
display_name(name) click to toggle source

Outputs formatted RI data for the class or method name.

Returns true if name was found, false if it was not an alternative could be guessed, raises an error if name couldn’t be guessed.

     # File lib/rdoc/ri/driver.rb, line 682
682:   def display_name name
683:     return true if display_class name
684: 
685:     display_method name if name =~ /::|#|\./
686: 
687:     true
688:   rescue NotFoundError
689:     matches = list_methods_matching name if name =~ /::|#|\./
690:     matches = classes.keys.grep(/^#{name}/) if matches.empty?
691: 
692:     raise if matches.empty?
693: 
694:     page do |io|
695:       io.puts "#{name} not found, maybe you meant:"
696:       io.puts
697:       io.puts matches.join("\n")
698:     end
699: 
700:     false
701:   end
display_names(names) click to toggle source

Displays each name in name

     # File lib/rdoc/ri/driver.rb, line 706
706:   def display_names names
707:     names.each do |name|
708:       name = expand_name name
709: 
710:       display_name name
711:     end
712:   end
expand_class(klass) click to toggle source

Expands abbreviated klass klass into a fully-qualified class. “Zl::Da” will be expanded to Zlib::DataError.

     # File lib/rdoc/ri/driver.rb, line 717
717:   def expand_class klass
718:     klass.split('::').inject '' do |expanded, klass_part|
719:       expanded << '::' unless expanded.empty?
720:       short = expanded << klass_part
721: 
722:       subset = classes.keys.select do |klass_name|
723:         klass_name =~ /^#{expanded}[^:]*$/
724:       end
725: 
726:       abbrevs = Abbrev.abbrev subset
727: 
728:       expanded = abbrevs[short]
729: 
730:       raise NotFoundError, short unless expanded
731: 
732:       expanded.dup
733:     end
734:   end
expand_name(name) click to toggle source

Expands the class portion of name into a fully-qualified class. See expand_class.

     # File lib/rdoc/ri/driver.rb, line 740
740:   def expand_name name
741:     klass, selector, method = parse_name name
742: 
743:     return [selector, method].join if klass.empty?
744: 
745:     "#{expand_class klass}#{selector}#{method}"
746:   end
find_methods(name) click to toggle source

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 searched for

     # File lib/rdoc/ri/driver.rb, line 754
754:   def find_methods name
755:     klass, selector, method = parse_name name
756: 
757:     types = method_type selector
758: 
759:     klasses = nil
760:     ambiguous = klass.empty?
761: 
762:     if ambiguous then
763:       klasses = classes.keys
764:     else
765:       klasses = ancestors_of klass
766:       klasses.unshift klass
767:     end
768: 
769:     methods = []
770: 
771:     klasses.each do |ancestor|
772:       ancestors = classes[ancestor]
773: 
774:       next unless ancestors
775: 
776:       klass = ancestor if ambiguous
777: 
778:       ancestors.each do |store|
779:         methods << [store, klass, ancestor, types, method]
780:       end
781:     end
782: 
783:     methods = methods.sort_by do |_, k, a, _, m|
784:       [k, a, m].compact
785:     end
786: 
787:     methods.each do |item|
788:       yield(*item) # :yields: store, klass, ancestor, types, method
789:     end
790: 
791:     self
792:   end
formatter() click to toggle source

Creates a new RDoc::Markup::Formatter. If a formatter is given with -f, use it. If we’re outputting to a pager, use bs, otherwise ansi.

     # File lib/rdoc/ri/driver.rb, line 798
798:   def formatter
799:     if @formatter_klass then
800:       @formatter_klass.new
801:     elsif paging? then
802:       RDoc::Markup::ToBs.new
803:     else
804:       RDoc::Markup::ToAnsi.new
805:     end
806:   end
in_path?(file) click to toggle source

Is file in ENV[‘PATH’]?

     # File lib/rdoc/ri/driver.rb, line 847
847:   def in_path? file
848:     return true if file =~ %\A/% and File.exist? file
849: 
850:     ENV['PATH'].split(File::PATH_SEPARATOR).any? do |path|
851:       File.exist? File.join(path, file)
852:     end
853:   end
interactive() click to toggle source

Runs ri interactively using Readline if it is available.

     # File lib/rdoc/ri/driver.rb, line 811
811:   def interactive
812:     puts "\nEnter the method name you want to look up."
813: 
814:     if defined? Readline then
815:       Readline.completion_proc = method :complete
816:       puts "You can use tab to autocomplete."
817:     end
818: 
819:     puts "Enter a blank line to exit.\n\n"
820: 
821:     loop do
822:       name = if defined? Readline then
823:                Readline.readline ">> "
824:              else
825:                print ">> "
826:                $stdin.gets
827:              end
828: 
829:       return if name.nil? or name.empty?
830: 
831:       name = expand_name name.strip
832: 
833:       begin
834:         display_name name
835:       rescue NotFoundError => e
836:         puts e.message
837:       end
838:     end
839: 
840:   rescue Interrupt
841:     exit
842:   end
list_known_classes() click to toggle source

Lists classes known to ri

     # File lib/rdoc/ri/driver.rb, line 858
858:   def list_known_classes
859:     classes = []
860: 
861:     stores.each do |store|
862:       classes << store.modules
863:     end
864: 
865:     classes = classes.flatten.uniq.sort
866: 
867:     page do |io|
868:       if paging? or io.tty? then
869:         io.puts "Classes and Modules known to ri:"
870:         io.puts
871:       end
872: 
873:       io.puts classes.join("\n")
874:     end
875:   end
list_methods_matching(name) click to toggle source

Returns an Array of methods matching name

     # File lib/rdoc/ri/driver.rb, line 880
880:   def list_methods_matching name
881:     found = []
882: 
883:     find_methods name do |store, klass, ancestor, types, method|
884:       if types == :instance or types == :both then
885:         methods = store.instance_methods[ancestor]
886: 
887:         if methods then
888:           matches = methods.grep(/^#{method}/)
889: 
890:           matches = matches.map do |match|
891:             "#{klass}##{match}"
892:           end
893: 
894:           found.push(*matches)
895:         end
896:       end
897: 
898:       if types == :class or types == :both then
899:         methods = store.class_methods[ancestor]
900: 
901:         next unless methods
902:         matches = methods.grep(/^#{method}/)
903: 
904:         matches = matches.map do |match|
905:           "#{klass}::#{match}"
906:         end
907: 
908:         found.push(*matches)
909:       end
910:     end
911: 
912:     found.uniq
913:   end
load_method(store, cache, klass, type, name) click to toggle source

Loads RI data for method name on klass from store. type and cache indicate if it is a class or instance method.

     # File lib/rdoc/ri/driver.rb, line 919
919:   def load_method store, cache, klass, type, name
920:     methods = store.send(cache)[klass]
921: 
922:     return unless methods
923: 
924:     method = methods.find do |method_name|
925:       method_name == name
926:     end
927: 
928:     return unless method
929: 
930:     store.load_method klass, "#{type}#{method}"
931:   end
load_methods_matching(name) click to toggle source

Returns an Array of RI data for methods matching name

     # File lib/rdoc/ri/driver.rb, line 936
936:   def load_methods_matching name
937:     found = []
938: 
939:     find_methods name do |store, klass, ancestor, types, method|
940:       methods = []
941: 
942:       methods << load_method(store, :class_methods, ancestor, '::',  method) if
943:         types == :class or types == :both
944: 
945:       methods << load_method(store, :instance_methods, ancestor, '#',  method) if
946:         types == :instance or types == :both
947: 
948:       found << [store, methods.compact]
949:     end
950: 
951:     found.reject do |path, methods| methods.empty? end
952:   end
method_type(selector) click to toggle source

Returns the type of method (:both, :instance, :class) for selector

     # File lib/rdoc/ri/driver.rb, line 957
957:   def method_type selector
958:     case selector
959:     when '.', nil then :both
960:     when '#'      then :instance
961:     else               :class
962:     end
963:   end
page() click to toggle source

Paginates output through a pager program.

     # File lib/rdoc/ri/driver.rb, line 968
968:   def page
969:     if pager = setup_pager then
970:       begin
971:         yield pager
972:       ensure
973:         pager.close
974:       end
975:     else
976:       yield $stdout
977:     end
978:   rescue Errno::EPIPE
979:   ensure
980:     @paging = false
981:   end
paging?() click to toggle source

Are we using a pager?

     # File lib/rdoc/ri/driver.rb, line 986
986:   def paging?
987:     @paging
988:   end
parse_name(name) click to toggle source

Extract 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

      method
      # File lib/rdoc/ri/driver.rb, line 997
 997:   def parse_name(name)
 998:     parts = name.split(/(::|#|\.)/)
 999: 
1000:     if parts.length == 1 then
1001:       if parts.first =~ /^[a-z]/ then
1002:         type = '.'
1003:         meth = parts.pop
1004:       else
1005:         type = nil
1006:         meth = nil
1007:       end
1008:     elsif parts.length == 2 or parts.last =~ /::|#|\./ then
1009:       type = parts.pop
1010:       meth = nil
1011:     elsif parts[2] != '::' or parts.last !~ /^[A-Z]/ then
1012:       meth = parts.pop
1013:       type = parts.pop
1014:     end
1015: 
1016:     klass = parts.join
1017: 
1018:     [klass, type, meth]
1019:   end
run() click to toggle source

Looks up and displays ri data according to the options given.

      # File lib/rdoc/ri/driver.rb, line 1024
1024:   def run
1025:     if @list_doc_dirs then
1026:       puts @doc_dirs
1027:     elsif @interactive then
1028:       interactive
1029:     elsif @names.empty? then
1030:       list_known_classes
1031:     else
1032:       display_names @names
1033:     end
1034:   rescue NotFoundError => e
1035:     abort e.message
1036:   end
setup_pager() click to toggle source

Sets up a pager program to pass output through. Tries the RI_PAGER and PAGER environment variables followed by pager, less then more.

      # File lib/rdoc/ri/driver.rb, line 1042
1042:   def setup_pager
1043:     return if @use_stdout
1044: 
1045:     pagers = [ENV['RI_PAGER'], ENV['PAGER'], 'pager', 'less', 'more']
1046: 
1047:     pagers.compact.uniq.each do |pager|
1048:       pager_cmd = pager.split.first
1049: 
1050:       next unless in_path? pager_cmd
1051: 
1052:       io = IO.popen(pager, 'w') rescue next
1053: 
1054:       next if $? and $?.exited? # pager didn't work
1055: 
1056:       @paging = true
1057: 
1058:       return io
1059:     end
1060: 
1061:     @use_stdout = true
1062: 
1063:     nil
1064:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.