PM_RESET = "\e[0m" PM_BOLD = "\e[1m" PM_GRAY = "\e[1;30m" PM_LGRAY = "\e[0;37m" def pm(obj, *options) # Print methods methods = obj.methods - (options.include?(:more) ? [] : Object.methods) filter = options.select {|opt| opt.kind_of? Regexp}.first methods = methods.select {|name| name =~ filter} if filter data = methods.sort.collect do |name| method = obj.method(name) args = "(" + case method.arity <=> 0 when 1 ("a"..(?a + method.arity - 1).chr).to_a.join(", ") when -1 ("a"..(?a - method.arity - 1).chr).to_a.join(", ") else "" end + ")" klass = $1 if method.inspect =~ /Method: (.*)#/ klass = $1 if klass =~ /\((.*)\)/ [name, args, klass] end max_name_length = data.collect {|item| item[0].size}.max max_args_length = data.collect {|item| item[1].size}.max data.each do |item| print " #{PM_BOLD}#{item[0].rjust(max_name_length)}#{PM_RESET}" print "#{PM_BOLD}#{item[1].ljust(max_args_length)}#{PM_RESET}" print " #{PM_BOLD}#{item[2]}#{PM_RESET} \n" end data.size end