# vim: filetype=ruby et ts=2 sw=2 ENV['TERM']='Eterm' ['irb/completion','rubygems','stringio','fileutils','enumerator'].each do |mod| IRB.conf[:LOAD_MODULES] ||= [] IRB.conf[:LOAD_MODULES] << mod unless IRB.conf.nil? or IRB.conf[:LOAD_MODULES].include?(mod) end ARGV.concat [ "--readline", "--prompt-mode", "simple" ] IRB.conf[:HISTORY_FILE] = File::expand_path("~/.irb.hist") IRB.conf[:SAVE_HISTORY] = 10000 IRB.conf[:AUTO_INDENT] = true IRB.conf[:USE_READLINE] = true # {{{ what? for Ruby # for background see: http://redhanded.hobix.com/inspect/stickItInYourIrbrcMethodfinder.html # and the original MethodFinder: http://www.nobugs.org/developer/ruby/method_finder.html require 'stringio' class Object # Clone fails on numbers, but they're immutable anyway def megaClone begin self.clone; rescue; self; end end end class MethodFinder def initialize( obj, *args ) @obj = obj @args = args end def ==( val ) MethodFinder.show( @obj, val, *@args ) end # Find all methods on [anObject] which, when called with [args] return [expectedResult] def self.find( anObject, expectedResult, *args ) anObject.methods.select { |name| anObject.method(name).arity == args.size }.select { |name| begin anObject.megaClone.method( name ).call(*args) == expectedResult rescue end } end # Pretty-prints the results of the previous method def self.show( anObject, expectedResult, *args ) $old_stderr = $stderr; $stderr = StringIO.new methods = find( anObject, expectedResult, *args ).each { |name| print "#{anObject.inspect}.#{name}" print "(" + args.map { |o| o.inspect }.join(", ") + ")" unless args.empty? puts " == #{expectedResult.inspect}" } $stderr = $old_stderr methods end end class Object def what?(*a) MethodFinder.new(self, *a) end end # }}} # {{{ ri def ri arg puts `ri #{arg}` end class Module def ri(meth=nil) if meth if instance_methods(false).include? meth.to_s puts `ri #{self}##{meth}` end else puts `ri #{self}` end end end # }}} def vi(*args); system "vi #{args.to_s}"; end def ls(*args) args.any? ? args : ['.']).map { |a| Dir.entries(a).delete_if{ |x| /^\./.match(File.basename(x)) } } end