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

···

--
Posted via http://www.ruby-forum.com/\.

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

Fred

···

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

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

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.

···

On 2007年12月25日Tuesday 19:19:11 Frederick Cheung wrote:

On 25 Dec 2007, at 10:40, Oscar Del ben wrote:
> 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

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

Fred

Dear,
  I will try this.

Thanks.

···

On 2007年12月25日Tuesday 19:50:09 BiHi wrote:

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?

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

Fred

···

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

Thanks.

On 2007年12月25日Tuesday 19:19:11 Frederick Cheung wrote:

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

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

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

Fred