From: Eugene Scripnik Date: 2003-01-04T03:10:28+09:00 Subject: Re: toplevel modules and classes Friday, January 3, 2003, 7:23:55 PM, you wrote: E>> OK, another question. Module#constants return constants accessible E>> in this module. But Class#constants produces the same output as E>> Object.constants (Class itself is an Object, right?). How do I get all t> no, no you don't have the same output Oh, sorry. I've tested on some standard classes and they actually don't have constants inside. E>> modules and classes defined in this particular class? t> but you can't use this directly, because of this problem t> pigeon% ruby -e 'class A; B = A = 12; end; p (A.constants - Object.constants)' t> ["B"] t> pigeon% Class#constants == self_constants + Object.constants t> something like this (it's strange for me to put classes in another class, t> why do you want to do this ?) Well, I just wanted to build classes/modules tree of my application. This structure is so complicated. And I wanted to do it in generalized way and also was surprised when I put another class/module into class and compiler found it OK. So, both module and class accept defining modules and classes inside them, but Class#constants and Module#constants behave in different way. That was second surprise. t> pigeon% cat b.rb t> #!/usr/bin/ruby t> class A t> class A; end t> class B; end t> end t> A.constants.each do |kl| t> a = A.const_get(kl) t> b = Object.const_defined?(kl) && Object.const_get(kl) t> puts a if a != b && a.kind_of?(Module) t> end t> pigeon% t> pigeon% b.rb t> A::A t> A::B t> pigeon% t> you must adapt it, if it's not a toplevel class -- Best regards, Eugene [team Enticla] mailto:Eugene.Scripnik@itgrp.net