Reflection of an unloaded class/object

K

Kyle Heon

------=_NextPart_000_003E_01C584CC.3C3358C0
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: 7bit

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
(e-mail address removed)



------=_NextPart_000_003E_01C584CC.3C3358C0--
 
R

Robert Klemme

Kyle Heon said:
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
 
K

Kyle Heon

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

http://wiki.rubyonrails.com/rails/show/HowToMakeSitemapWithIntrospection
http://wiki.rubyonrails.com/rails/show/DiscoveringControllersAndActions

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
(e-mail address removed)


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


Kyle Heon said:
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
 
A

Austin Ziegler

My problem with those solutions is that it seems awfully wasteful to "loa= d"
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 assumpti=
on?

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

-austin
--=20
Austin Ziegler * (e-mail address removed)
* Alternate: (e-mail address removed)
 

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
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top