[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

which class defined

raving_ruby_rider

2/15/2006 1:51:00 PM

Hi,

I need to load scripts dynamically.

Is there a way to know about what
classes were defined by loading a script?

If not, can the Ruby system be asked for a collection
of subclasses for a particular Class?

thx

7 Answers

Ara.T.Howard

2/15/2006 3:38:00 PM

0

Ross Bamford

2/15/2006 3:42:00 PM

0

On Wed, 2006-02-15 at 22:53 +0900, raving_ruby_rider wrote:

> Is there a way to know about what
> classes were defined by loading a script?
>

I've done something like this before:

sc, ec = [], []
# => [[], []]

ObjectSpace.each_object(Class) { |c| sc << c }
# => 471
require 'generator'
# => true
ObjectSpace.each_object(Class) { |c| ec << c }
# => 473

new_classes = ec - sc
# => [SyncEnumerator, Generator]

> If not, can the Ruby system be asked for a collection
> of subclasses for a particular Class?

See above (the argument to each_object).

--
Ross Bamford - rosco@roscopeco.REMOVE.co.uk



Joel VanderWerf

2/15/2006 9:31:00 PM

0

ara.t.howard@noaa.gov wrote:
> On Wed, 15 Feb 2006, raving_ruby_rider wrote:
>
>> Is there a way to know about what
>> classes were defined by loading a script?
>
> see dynaload
>
> http://rubyforge.org/frs/?group_id=1024&relea...
> http://codeforpeople.com/lib/ruby/dynaload/dynaload-0....

There's also
http://raa.ruby-lang.org/proje...
http://redshift.sourceforge.net/script/doc/...

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


Dave Cantrell

2/16/2006 2:51:00 AM

0

Ross Bamford wrote:
> On Wed, 2006-02-15 at 22:53 +0900, raving_ruby_rider wrote:
>
>> Is there a way to know about what
>> classes were defined by loading a script?
>>
>
> I've done something like this before:
>
> sc, ec = [], []
> # => [[], []]
>
> ObjectSpace.each_object(Class) { |c| sc << c }
> # => 471
> require 'generator'
> # => true
> ObjectSpace.each_object(Class) { |c| ec << c }
> # => 473
>
> new_classes = ec - sc
> # => [SyncEnumerator, Generator]
>
>> If not, can the Ruby system be asked for a collection
>> of subclasses for a particular Class?
>
> See above (the argument to each_object).
>

Heh. If you make your terminal black and green and run this:

ObjectSpace.each_object(Object) { |o| puts o }

... you will see the truth of the Matrix. :)

-dave


raving_ruby_rider

2/16/2006 9:36:00 AM

0

thx 2 all.

i like the Script encapsulation

George Ogata

2/16/2006 12:47:00 PM

0

Dave Cantrell <ruby-talk@deadcantrant.com> writes:

> Heh. If you make your terminal black and green and run this:
>
> ObjectSpace.each_object(Object) { |o| puts o }
>
> .. you will see the truth of the Matrix. :)
>
> -dave

You get used to it. I don't even see the code. All I see is Symbol,
String, Array, ...


Cypher.

Gene Tani

2/16/2006 2:25:00 PM

0


George Ogata wrote:
> Dave Cantrell <ruby-talk@deadcantrant.com> writes:
>
> > Heh. If you make your terminal black and green and run this:
> >
> > ObjectSpace.each_object(Object) { |o| puts o }
> >
> > .. you will see the truth of the Matrix. :)
> >
> > -dave
>
> You get used to it. I don't even see the code. All I see is Symbol,
> String, Array, ...
>

These show what gets mixed in from where:
http://www.insula.cz/dali/materi...
http://www.cafepress.com/mathomhou...