Determining the Source File of a Class

A

Alan Gutierrez

I'm trying to debug a bug where I seem to have a class that has two
defintions, the one I know of, and another one, somewhere, the one I'm
getting when I attempt to use the class.

Given a class, is there a way to get name of the file in which it was
defined?

MyClass.defintion_file

Something like that?
 
R

Ryan Davis

I'm trying to debug a bug where I seem to have a class that has two =
defintions, the one I know of, and another one, somewhere, the one I'm =
getting when I attempt to use the class.
=20
Given a class, is there a way to get name of the file in which it was = defined?
=20
MyClass.defintion_file
=20
Something like that?

Classes in ruby are "open", which means that they can be extended at any =
time. So there isn't really a "definition" (at least, for a single =
location) of a given class.

You also have the case where something isn't opened to have stuff added =
to it, but instead it can be extended by modules instead.

If you want, you can play with the reflective hooks in Module: =
method_added, included, extended, etc.
 
A

Alan Gutierrez

Ryan said:
Classes in ruby are "open", which means that they can be extended at any time. So there isn't really a "definition" (at least, for a single location) of a given class.

Thank you. That answers my question.
You also have the case where something isn't opened to have stuff added to it, but instead it can be extended by modules instead.

If you want, you can play with the reflective hooks in Module: method_added, included, extended, etc.

Sounds like fire hose, but I'm sure there's a clever Ruby way to control
the torrent.

Fortunately, I seem to have found the other definition that is being
invoked using `find` and `grep`.
 
K

kent yip

Date: Sat=2C 24 Jul 2010 06:30:10 +0900
From: (e-mail address removed)
Subject: Re: Determining the Source File of a Class
To: (e-mail address removed)
=20
fintions=2C the one I know of=2C and another one=2C somewhere=2C the one I'=
m getting when I attempt to use the class.any time. So there isn't really a "definition" (at least=2C for a single lo=
cation) of a given class.
=20
Thank you. That answers my question.
=20
_added=2C included=2C extended=2C etc.
=20
Sounds like fire hose=2C but I'm sure there's a clever Ruby way to contro= l=20
the torrent.
=20
Fortunately=2C I seem to have found the other definition that is being=20
invoked using `find` and `grep`.
=20
--=20
Alan Gutierrez - (e-mail address removed) - http://twitter.com/bigeasy
=20
=20
_________________________________________________________________
MSN Dating: Find someone special. Start now.
http://go.microsoft.com/?linkid=3D9734384=
 

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

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top