Skip to content

Commit e36b99c

Browse files
authored
support finding "source" from IRB sessions
1 parent 836d704 commit e36b99c

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

lib/method_source.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ def self.comment_helper(source_location, name=nil)
4949
# @return [Array<String>] the contents of the file
5050
# @raise [SourceNotFoundError]
5151
def self.lines_for(file_name, name=nil)
52+
if file_name == '(irb)' && defined?(IRB)
53+
# we can't memoize, because this "file" is always growing. presumably if you're
54+
# overwriting methods in an IRB session, you're not too concerned about performance
55+
# anyway
56+
return IRB.CurrentContext.io.instance_variable_get(:@line).join.split(/(?<=\n)/)
57+
end
58+
5259
@lines_for_file ||= {}
5360
@lines_for_file[file_name] ||= File.readlines(file_name)
5461
rescue Errno::ENOENT => e

0 commit comments

Comments
 (0)