Issue #8751 has been updated by banister (john mair).


We can already do a fairly reliable method extraction in Pry, we simply start reading from the first line of the method definition until we get a complete expression, there are a few situations where this breaks but in 90% of cases (in my experience) it works fine. Regarding (c), this is available already in Pry via the `show-source` command (it also shows source for classes and modules, not just methods). I think it might be useful in some situations to get the column numbers but it's also not too difficult to just 'clean up' the source around the method source_location in cases where the method definition is preceded by other code on the same line.  


----------------------------------------
Feature #8751: Add offsets to method#source_location
https://bugs.ruby-lang.org/issues/8751#change-41034

Author: tenderlovemaking (Aaron Patterson)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Hello,

I would like to have byte offsets returned on the source_location for methods.  For example:

def foo(&b)
  b.source_location # => [file_name, line_number, start_byte, end_byte]
end

If we had the start and end byte for a method or proc, then we could find the source for methods and procs in each file.  There are some cases (like with heredocuments) where the "end of the method" could be after the `end` keyword.  But I think if we just have offsets for the start of `def` and the end of `end`, I think it would cover 99% of usecases.


-- 
http://bugs.ruby-lang.org/