[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Reflection of an unloaded class/object

Kyle Heon

7/10/2005 1:22:00 AM

Is it possible to look inside an object without it having already been
loaded into memory? In other words, can you do so by file path instead of
having it look at what is currently loaded?

Kyle Heon
kheon@comcast.net


3 Answers

Robert Klemme

7/10/2005 10:08:00 AM

0


"Kyle Heon" <kheon@comcast.net> schrieb im Newsbeitrag
news:20050710012201.63AE733A20@beryllium.ruby-lang.org...
> Is it possible to look inside an object without it having already been
> loaded into memory? In other words, can you do so by file path instead of
> having it look at what is currently loaded?

What exactly do you mean by "look inside an object"? What is it that you
are trying to achieve?

Kind regards

robert

Kyle Heon

7/10/2005 12:10:00 PM

0

I want to build a navigation system for my Rails app that using techniques
found in these articles:

http://wiki.rubyonrails.com/rails/show/HowToMakeSitemapWithInt...
http://wiki.rubyonrails.com/rails/show/DiscoveringControllers...

My problem with those solutions is that it seems awfully wasteful to "load"
each controller just so that it's visible to the ObjectSpace object. My
understanding is at that point it's loaded, is this an incorrect assumption?

In C# you can use Reflection by pointing to an assembly (dll) and I'm
curious if Ruby has something similar.

So, taking something from the above options here is some really rough psuedo
code:

Find.find( RAILS_ROOT + 'app/controllers' ) do |file_name|
open file-_name
if of type Admin::BaseController
add to controllers array
end

loop controllers array
output found controllers.

If I'm going about this completely wrong and you know how I can do this
better by all means, let me know.

As I said, I'm learning Ruby and I'm just trying to learn how to do stuff. I
would imagine I'm not doing things the best way possible.

Kyle Heon
kheon@comcast.net


-----Original Message-----
From: Robert Klemme [mailto:bob.news@gmx.net]
Sent: Sunday, July 10, 2005 6:11 AM
To: ruby-talk ML
Subject: Re: Reflection of an unloaded class/object


"Kyle Heon" <kheon@comcast.net> schrieb im Newsbeitrag
news:20050710012201.63AE733A20@beryllium.ruby-lang.org...
> Is it possible to look inside an object without it having already been
> loaded into memory? In other words, can you do so by file path instead
> of having it look at what is currently loaded?

What exactly do you mean by "look inside an object"? What is it that you
are trying to achieve?

Kind regards

robert




Austin Ziegler

7/10/2005 1:48:00 PM

0

On 7/10/05, Kyle Heon <kheon@comcast.net> wrote:
> My problem with those solutions is that it seems awfully wasteful to "load"
> each controller just so that it's visible to the ObjectSpace object. My
> understanding is at that point it's loaded, is this an incorrect assumption?

No, it isn't an incorrect assumption. And no, there isn't a clean way
to do this.

-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca