From: Pit Capitain Date: 2005-01-29T01:10:46+09:00 Subject: Re: : How can I find the filename where a class is defined? Michael Neumann schrieb: > > class Object > class << self > attr_accessor :classdef_in_file > > alias __old_inherited inherited > def inherited(klass) > klass.classdef_in_file = caller.last.split(":").first > __old_inherited(klass) > end > end > end This is a nice idea! Note that it doesn't work on Windows, though, cause there you have filenames with colons ("C:/xxx"). You could change the line > klass.classdef_in_file = caller.last.split(":").first to > klass.classdef_in_file = caller.last.sub(/:\d+$/, "") BTW: now I can finally get rid of all those ugly if $0 == __FILE__ end Code :-) Thanks for the reminder, Pit