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
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
···
On 8/8/05, Steven D. Arnold <stevena@neosynapse.net> wrote:
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?
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca
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
···
--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting