From: Brian Candler Date: 2004-10-06T18:05:42+09:00 Subject: Re: Use ri from irb ? On Wed, Oct 06, 2004 at 09:00:57AM +0900, Bill Atkins wrote: > Or maybe > > # untested > class RiDriver > alias_method :oldpa, :process_args > > def process_args *args > args = ARGV if args.nil? > oldpa *args > end > end > > Then you can just do "ri.process_args arg_array" Erm, except the method 'oldpa' still doesn't take any arguments, so what's it going to do with the ones you're passing to it! I can't see what you're trying to achieve there. The method oldpa/process_args uses the contents of the ARGV constant directly. Those are the arguments passed on the command line, not anything to do with method call arguments. Anyway, here's a better solution to go in .irbrc: def ri(*names) require 'rdoc/ri/ri_driver' oargv = ARGV.dup ARGV.replace names.map{|n| n.to_s} RiDriver.new.process_args ensure ARGV.replace oargv end * putting require _inside_ the method means that the library won't be loaded until it's first used * using 'replace' gets rid of the warnings about constants being changed * using to_s means that class names don't need to be quoted: irb(main):001:0> ri Enumerable ------------------------------------------------------ Class: Enumerable The +Enumerable+ mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The ... etc Regards, Brian.