#! /usr/bin/env ruby # # $Id: classdescr.rb,v 1.8 2004/02/10 19:08:27 fukumoto Exp $ # if begin require 'format'; true; rescue LoadError; false end def printout(kname, mlist) ex = < 1 printout("INHERITS:", k.ancestors[1..-1].join(", ")) end a = [] ObjectSpace.each_object(Module) { |mod| a << mod.inspect if mod < k } printout("INHERITED BY:", a.sort.join(", ")) method_list = [] k.ancestors.each do |i| dif = i.singleton_methods - method_list next if dif.empty? next if i.equal? Kernel and not $VERBOSE printout("CLASS METHODS OF #{i.to_s}:", dif.sort.join(', ')) method_list |= dif end printout("PUBLIC INSTANCE METHODS:", k.public_instance_methods(false).sort.join(", ")) method_list = k.public_instance_methods(false) k.ancestors[1..-1].each do |i| dif = i.instance_methods(false) - method_list printout((i.kind_of?(Class) ? "INHERITS" : "INCLUDES") + " #{i.to_s}:", dif.sort.join(", ")) method_list |= dif end const = k.constants k.ancestors[1..-1].each do |x| const -= x.constants end printout("CONSTANTS:", const.sort.join(", ")) k.ancestors[1..-1].each do |i| next if i.equal? Object and not $VERBOSE const = i.constants i.ancestors[1..-1].each do |x| const -= x.constants end next if const.empty? printout((i.kind_of?(Class) ? "INHERITS" : "INCLUDES") + " #{i.to_s}:", const.sort.join(", ")) end end while a = ARGV.shift case a when /^-r(.*)/ require($1.empty? ? ARGV.shift : $1) when /^-v/ $VERBOSE = true else ARGV.unshift(a) break end end ARGV.each do |i| (STDERR.puts "#{i} is not a class"; next) if not (/^[A-Z]\w*(::[A-Z]\w*)*$/ === i) k = eval i (STDERR.puts "#{i} is not a class"; next) if not k.kind_of? Module print_description(k) print "\n" end