Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/representable/debug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,17 @@ def _inspect_function(func)
return func.extend(Pipeline::Debug).inspect if func.is_a?(Collect)
return func unless func.is_a?(Proc)

File.readlines(func.source_location[0])[func.source_location[1]-1].match(/^\s+(\w+)/)[1]
location = func.source_location
return func.inspect unless location && location[1] > 0

line = nil
File.open(location[0], "rb") do |file|
location[1].times { break unless (line = file.gets) }
end
name = line && line.match(/^\s*(\w+)/)
name ? name[1] : func.inspect
rescue SystemCallError, IOError
func.inspect
end
end
end