Dynamically determining a class or module's file name

Hi all,

This may seem an odd question but, is there a way to dynamically
determine the filename that a class and/or module is written in?

In other words, if I have a file called “myclass.rb”, and within that
file I have the class called “SomeClass”, is there a Module or Class
method that let’s me determine the name of the file?

e.g. imaginary method

class SomeClass
puts sourcefile -> myclass.rb
end

Regards,

Dan

But a class or module can be written in multiple files.

I believe that the methods themselves are marked with file and line
information; this is available to the debugger. I recall that someone
came up with a way to access these from Ruby.

Of course, for your example you could just use FILE and LINE:

class SomeClass
puts "file #{FILE} line #{LINE}"
end

···

On Wednesday 24 July 2002 12:05 pm, Daniel Berger wrote:

Hi all,

This may seem an odd question but, is there a way to dynamically
determine the filename that a class and/or module is written in?


Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE