Created
October 25, 2011 16:57
-
-
Save betawaffle/1313480 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pry.instance_eval do | |
def show_lines(file, line_num, klass, num = nil) | |
if file =~ /(\(.*\))|<.*>/ || file == "" || file == "-e" | |
output.puts "Cannot find local context. Did you use `binding.pry` ?" | |
next | |
end | |
Pry.output.puts "\n\e[1mFrom:\e[0m #{file} @ line #{line_num} in #{klass}:\n\n" | |
if num | |
i_num = num.to_i | |
else | |
i_num = 5 | |
end | |
File.open(file).each_with_index do |line, index| | |
line_n = index + 1 | |
next unless line_n > (line_num - i_num - 1) | |
break if line_n > (line_num + i_num) | |
if line_n == line_num | |
code =" =>#{line_n.to_s.rjust(3)}: #{line.chomp}" | |
if Pry.color | |
code = CodeRay.scan(code, :ruby).term | |
end | |
output.puts code | |
code | |
else | |
code = "#{line_n.to_s.rjust(6)}: #{line.chomp}" | |
if Pry.color | |
code = CodeRay.scan(code, :ruby).term | |
end | |
output.puts code | |
code | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment