-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gavin Kistner wrote:
>> Suppose I have a ruby file with a single class. Is it 
>> possible to write a
>> ruby script that can extract the class name from the file?
> [...]
>> Is it possible to extract the class name via reflection?
> 
> Well, here's one terrible idea. (It's 'terrible' because it's brittle,
> and only works if no other files defining new classes have been defined,
> and will break if a new Ruby release defines a new class.)

I agree.

I just wanted to share what I had in mind, which will not break because
of a new ruby version (I guess):

old_classes = self.class.constants.find_all {|x|
self.class.const_get(x).class == Class }.compact

require'my_lib'

all_classes = self.class.constants.find_all {|x|
self.class.const_get(x).class == Class }.compact

new_classes = (all_classes - old_classes).collect {|x|
self.class.const_get(x) }

Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFBveV9S2Eui6zfdQRAlAOAKCjHM1eUg3ueMnoQ7krW2D5RBBmxgCdHyTs
olOXERUvErsSh6GxLhC8s34=
=UYzZ
-----END PGP SIGNATURE-----