From: "John W. Long" Date: 2004-06-20T05:11:49+09:00 Subject: Re: Which classes are installed on my system? --------------060001050107000204080509 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Stephan K�mper wrote: > Mark Hubbart wrote: > >> On Jun 18, 2004, at 11:14 AM, Lennon Day-Reynolds wrote: >> >>> For a list of classes, just try the following code snippet: >>> >>> ObjectSpace.each_object(Class) do |c| >>> puts c >>> end >> >> >> This will give a list of loaded classes. Complex, for instance will >> not be visible until you 'require "complex"' (or "mathn", etc). > > On second thought Todd's question isn't *that* easy to answer I think. The attached gives a better idea when you run it on windows. Be careful with it. It comes with no warranties. The fact that it requires almost every library on your system make cause serious problems depending on the libraries you have installed. It worked for me. Shouldn't be that hard to get the script to work on linux. -- John --------------060001050107000204080509 Content-Type: text/plain; name="list-classes.rb" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="list-classes.rb" def get_classes(filename=nil) r = %{-r"#{filename}"} unless filename.nil? #puts filename print '.' $stdout.flush `ruby #{r} -e "ObjectSpace.each_object(Class) { |klass| print klass.to_s + ',' }"`.split(',').uniq.sort end def a_to_h(a, filename) h = {} a.each { |a| h[a] = filename } h end puts 'Starting' std = get_classes list = a_to_h(std, '(none)') Dir.chdir("C:/ruby/lib/ruby/1.8") files = Dir['**/*.rb'].delete_if { |f| [ 'rubyunit.rb', 'finalize.rb', 'multi-tk.rb', 'profile.rb', 'debug.rb', 'tracer.rb', 'webrick/httpservlet/cgi_runner.rb', 'bigdecimal/newton.rb', 'bigdecimal/nlsolve.rb', 'irb/cmd/fork.rb', 'irb/cmd/subirb.rb', 'irb/completion.rb', 'irb/ext/history.rb', 'irb/ext/multi-irb.rb', 'irb/ext/tracer.rb', 'irb/ext/use-loader.rb', 'irb/extend-command.rb', 'irb/ws-for-case-2.rb', 'shell/builtin-command.rb', 'shell/filter.rb', 'shell/system-command.rb', 'webrick/httpauth/authenticator.rb', 'webrick/https.rb', 'webrick/httpservlet/filehandler.rb', 'xmlrpc/config.rb', 'yaml/dbm.rb', 'yaml/rubytypes.rb', 'yaml/types.rb' ].include?(f) or (f =~ /test/) or (f =~ /^tk/) or (f =~ /^rexml/) }.sort files.each { |f| a = get_classes(f) a = a - std h = a_to_h(a, f) list.update(h) } list = list.sort { |a,b| a[0] <=> b[0] } klasses = {} list.each { |item| klasses[item[0]] ||= [] klasses[item[0]] << item[1] } klasses = klasses.sort { |a,b| a[0].downcase <=> b[0].downcase } print "\n" puts "Finished\n\n" puts "Classes:\n\n" klasses.each { |item| c = item[0] f = item[1] s = "#{c.to_s} : " l = s.length puts "#{s}#{f.first}" f[1..-1].each { |i| puts (" " * l) + i } } --------------060001050107000204080509--