Ruby: Can a Function Know It’s Own Source File?
I got to wondering this weekend: can a function know about it’s own source file in Ruby? The reason I was wondering this is because I’ve found that when working on someone else’s Ruby source code the ease with which mixins can be made sometimes leads to code that’s very difficult to trace.
Stack a few layers of inheritance together, stick some mixins into each level and then try and locate the original location of my_obj.coerce()… I tend to have to resort to TextMate’s global Find to search through the whole project (and woe is me if it contains multiple coerce() functions in different files). True story, that example.
What I’d like, and haven’t yet been able to discern a means to do, is either:
Kernel::source_file( my_obj.coerce )
or
my_obj.coerce.source_file()
or something along those lines which would spit back:
/var/src/my_proj/modules/coercion_functions.rb
Does this already exist? Am I missing something trivial?
