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

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

Thanks.

Magicloud Wang wrote:

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

On 25 Dec 2007, at 10:40, Oscar Del ben wrote:

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

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

Dear,
I think this disappeared in rails 2?

Thanks.

Dear,
I will try this.

Thanks.

On 25 Dec 2007, at 20:52, Magicloud Wang wrote:

Dear,
I think this disappeared in rails 2?

Nope, definitely still there. Was fiddling with it just a few days ago.

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs