From: Austin Ziegler Date: 2005-08-08T14:13:03+09:00 Subject: Re: how to determine path for object's type? On 8/8/05, Steven D. Arnold 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? 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 -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca