how to determine path for object's type?

  • Thread starter Steven D. Arnold
  • Start date
S

Steven D. Arnold

Hi,

I have an object that I think is loading its class definition from the
wrong file. I.e. there may be two files in the filesystem that define
a similarly-named class, and I may be instantiating my object using the
wrong class. This leads to the question: Given an object, how can I
determine the file in which the object's class is defined?

Thanks,
steve
 
A

Austin Ziegler

I have an object that I think is loading its class definition from the
wrong file. I.e. there may be two files in the filesystem that define
a similarly-named class, and I may be instantiating my object using the
wrong class. This leads to the question: Given an object, how can I
determine the file in which the object's class is defined?

Short answer: you can't.

Long answer: Ruby objects aren't related to the path from which they
are created. Files are simply code containers. You may be able to add
some code specifically to your suspect class files that let you print
__FILE__ from the defining file (e.g., something like def initialize;
puts "Creating from #{__FILE__}"; end), but that has to be put in the
code. Alternately, if you know of a way to cause an exception to be
thrown in or through the object in question, the backtrace involved
will generally print the file from which the object method was
defined.

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

Stephen Kellett

wrong class. This leads to the question: Given an object, how can I
determine the file in which the object's class is defined?

If you are running Windows you could use Ruby Bug Validator to capture
the application flow trace and examine that. This will show you class
names, filenames, variables and parameters, etc.

http://www.softwareverify.com

Stephen
 

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

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top