list of all class names 
Author Message
 list of all class names

Hi,

method "methods" gives me all methods for an object
irb(main):005:0> methods
["public", "to_s", "include", "private", "irb_source", "irb_fork",
[...]
irb(main):006:0> "string".methods
["~", "==", "slice", "squeeze", "strip", "%", "intern", "===",
"capitalize!", "t

How can I get a list of all classes in existance (in the given location
and point in time)?

I need this to prevent naming colisions when generating code.

Tobi

--
http://www.*-*-*.com/



Sat, 03 Jul 2004 19:46:56 GMT  
 list of all class names

Quote:

> Hi,

Hi,

Quote:
> How can I get a list of all classes in existance (in the given location
> and point in time)?

A simple way is to use ObjectSpace.each_object(Class)
as in

def all_classes
  classes = []
  ObjectSpace.each_object(Class) {|c| classes << c}
  classes.uniq
end

/Robert



Sat, 03 Jul 2004 19:52:16 GMT  
 list of all class names

Quote:

> def all_classes
>   classes = []
>   ObjectSpace.each_object(Class) {|c| classes << c}
>   classes.uniq
> end

Oops, uniq shouldn't be needed there...

/Robert



Sat, 03 Jul 2004 20:18:50 GMT  
 list of all class names
Robert,

Quote:
> def all_classes
>   classes = []
>   ObjectSpace.each_object(Class) {|c| classes << c}
>   classes.uniq
> end

Thanks!

Tobi

--
http://www.pinkjuice.com/



Sat, 03 Jul 2004 22:37:21 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Class variables in parent and child classes with the same name

2. Class from name of class

3. How to call a class method from a string representing a class name

4. Q: Tcl list commands and C++ List class

5. typo in class name?

6. Name Classes

7. class from name

8. Filename class name suggestion

9. Naming of Namespaces and Classes

10. Upper case class method names

11. newbie question, assigning object to class name

12. Class Name of AppFrame

 

 
Powered by phpBB® Forum Software