On 9/6/08, Yukihiro Matsumoto <matz / ruby-lang.org> wrote:
> Hi,
>
>  In message "Re: [ruby-core:18452] [ANN] Ruby 1.9.1 feature freeze"
>
>     on Fri, 5 Sep 2008 01:13:56 +0900, "Roger Pack" <rogerpack2005 / gmail.com> writes:
>
>  |Would it be possible to have a few patches applied before freeze [if
>  |possible]-I know I would use them [for being able to run racc against
>  |the original method definitions, etc.] :)
>  |
>  |http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/12598
>
>
> This is a proposal to add __file__ and __line__ methods to Method and
>  Proc objects.  Issues are:
>
>   * the method names.  I don't think proposed names that are
>     surrounded by underscores are appropriate.
>   * non-Ruby defined methods/procs.  the patch raises TypeError, but
>     is it really appropriate?  Should they return nil for such cases?
>   * use-case.  the proposal comes with use-case sourceref.rb, but any
>     other use case?
>


RSpec currently uses eval("caller(0)", @a_proc_instance) to simulate
this behavior.
I had not seen this proposal before, but I like it.
I looked into this while working on RSpec for Rubinius, and this seems
to be the only way to determine where a particular block_pass or proc
was created.

RSpec cares about this because (as one example) it allows users to
specify 'examples' to run by regexp against their description.

These 'examples' could be in any spec file, so it uses what I have
taken to calling the 'declaration trace' .. in other words, what you
get when you eval Kernel#caller with a proc as binding.

Using eval for this is slow and ugly; it would be nice to have a clean
feature to implement.
I considered proposing Proc#caller when I first encountered this, but
__file__ and __line__ are nice.

While I am on the subject, here is the bug ticket I filed related to this:
http://redmine.ruby-lang.org/issues/show/146