Ruby irb を便利に使う
http://www.rubygarden.org/ruby?Irb/TipsAndTricks
より。以前から irb は使い勝手が悪いと感じていたけど、タブ補完も ri もちゃんとできるのね。
~/.irbrc
#/usr/bin/env ruby # ri を使えるようにする def do_ri(arg) pager = (ENV["PAGER"] or "less") cmd = ("refe #{arg} | nkf -w | #{pager}") puts cmd system(cmd) end class Object def ri(word=nil) if word do_ri(word) else do_ri(self.class.to_s) end end end class Module def ri(meth=nil) if meth if instance_methods(false).include? meth.to_s do_ri "#{self}##{meth}" else super end else do_ri "#{self}" end end end # 直前の計算結果を保持する変数 _ を有効にする IRB.conf[:EVAL_HISTORY] = 1000 IRB.conf[:SAVE_HISTORY] = 100 # ヒストリーを有効にする HISTFILE = "~/.irb.hist" MAXHISTSIZE = 100 begin if defined? Readline::HISTORY histfile = File::expand_path( HISTFILE ) if File::exists?( histfile ) lines = IO::readlines( histfile ).collect {|line| line.chomp} puts "Read %d saved history commands from %s." % [ lines.nitems, histfile ] if $DEBUG || $VERBOSE Readline::HISTORY.push( *lines ) else puts "History file '%s' was empty or non-existant." % histfile if $DEBUG || $VERBOSE end Kernel::at_exit { lines = Readline::HISTORY.to_a.reverse.uniq.reverse lines = lines[ -MAXHISTSIZE, MAXHISTSIZE ] if lines.nitems > MAXHISTSIZE $stderr.puts "Saving %d history lines to %s." % [ lines.length, histfile ] if $VERBOSE || $DEBUG File::open( histfile, File::WRONLY|File::CREAT|File::TRUNC ) {|ofh| lines.each {|line| ofh.puts line } } } end end # タブ補完を有効にする require 'irb/completion' ARGV.concat [ "--readline", "--prompt-mode", "simple" ] # IPython をまねて edit def edit tfile = Tempfile.new("irb") system("vi " + tfile.path) if File.readable?(tfile.path) load(tfile.path) end end