How to know what class are there in a script file?

M

Magicloud Wang

Dear,
I mean after I 'load' or 'require' a file, How to know what classes I have
got?

Thanks.
 
O

Oscar Del ben

Magicloud said:
Dear,
I mean after I 'load' or 'require' a file, How to know what classes I
have
got?

Thanks.


I think there's no way of doing that, you can view the methods for a
class or object if you want

Oscar
 
F

Frederick Cheung

I think there's no way of doing that, you can view the methods for a
class or object if you want

activesupport has something like that. Have a look at
Dependencies#new_constants_in

Fred
 
B

BiHi

The activesupport Dependency thing is really nice since it works with
any constant, but if you really want the classes only, this seems to
do the trick:

require 'enumerator'

klasses_before = Enumerable::Enumerator.new(ObjectSpace, :each_object,
Class).to_a

require 'open-uri'

new_klasses = Enumerable::Enumerator.new(ObjectSpace, :each_object,
Class).to_a - klasses_before

p new_klasses
 

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,274
Messages
2,571,367
Members
48,060
Latest member
JerrodSimc

Latest Threads

Top