Which classes are installed on my system?

T

Todd Gardner

Hello everyone,

Even though these seem extremely silly and simple questions, I haven't
yet seen this information in the FAQ or on the Web. I must be looking
in the wrong places.

For general information I have looked at
Http://dev.rubycentral.com/book/builtins.html however, my question is
about my specific system.

How do I see the list of all the classes or methods installed on my
specific system?

Can I determine proper usage of a specific method installed on my
system using a man page or something similar?

Thank you,

Todd
 
M

Mark Hubbart

Hello everyone,

Even though these seem extremely silly and simple questions, I haven't
yet seen this information in the FAQ or on the Web. I must be looking
in the wrong places.

For general information I have looked at
Http://dev.rubycentral.com/book/builtins.html however, my question is
about my specific system.

How do I see the list of all the classes or methods installed on my
specific system?

If you have ri installed, run `ri -c` to get a list of known classes.
If the ri database was made properly, It will list allt eh classes
installed with Ruby.
Can I determine proper usage of a specific method installed on my
system using a man page or something similar?

`ri SomeObject#some_method` or `ri SomeObject::some_method`.

If you don't have ri installed (it comes standard with recent versions
of Ruby) check out the stdlib docs at http://www.ruby-doc.org/stdlib/

HTH,
Mark
 
L

Lennon Day-Reynolds

For a list of classes, just try the following code snippet:

ObjectSpace.each_object(Class) do |c|
puts c
end

If you want more detail on a given class, you can use 'ri', as Mark
recommended, or just try 'Klassname.instance_methods'.

Lennon
 
M

Mark Hubbart

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).

cheers,
Mark
 
S

Stephan Kämper

Mark said:
This will give a list of loaded classes. Complex, for instance will not
be visible until you 'require "complex"' (or "mathn", etc).

cheers,
Mark

So much is true, however if you 'require "whatever"' and "whatever" is
unknown to ri - perhap noone ever bother do write any documentation [1]
- then 'ri -c' won't tell you about that I guess.

On second thought Todd's question isn't *that* easy to answer I think.

Happy rubying

Stephan

[1] Of course, noone would ever even think of not documenting h(is|er)
software...
 
J

John W. Long

--------------060001050107000204080509
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
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--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,375
Latest member
FelishaCma

Latest Threads

Top