modulus approach for show-method working 100%

This commit is contained in:
John Mair 2011-05-24 23:02:29 +12:00
parent 07046765ee
commit 54f4f3e797
3 changed files with 10 additions and 5 deletions

View File

@ -62,7 +62,10 @@ class Pry
code = strip_comments_from_c_code(code) code = strip_comments_from_c_code(code)
when :ruby when :ruby
if meth.source_location.first == "(pry)" if meth.source_location.first == "(pry)"
code = strip_leading_whitespace(Pry.expr_store[meth.source_location.last]) bucket = (meth.source_location.last / 1000) * 1000
line = meth.source_location.last % 1000
p = Pry.new(:input => StringIO.new(Pry.expr_store[bucket].each_line.to_a[line..-1].join)).r(target)
code = strip_leading_whitespace(p)
else else
code = strip_leading_whitespace(meth.source) code = strip_leading_whitespace(meth.source)
end end

View File

@ -253,8 +253,8 @@ class Pry
@should_load_rc = true @should_load_rc = true
@rc_loaded = false @rc_loaded = false
@cli = false @cli = false
@current_expr = -1 @current_expr = 0
@expr_store = [] @expr_store = {}
end end
# Basic initialization. # Basic initialization.

View File

@ -191,8 +191,10 @@ class Pry
# This also sets the `_` local for the session. # This also sets the `_` local for the session.
expr = r(target) expr = r(target)
Pry.expr_store << expr Pry.expr_store[Pry.current_expr] = expr
set_last_result(target.eval(expr, "(pry)", Pry.current_expr += 1), target) result = set_last_result(target.eval(expr, "(pry)", Pry.current_expr), target)
Pry.current_expr += 1000
result
rescue SystemExit => e rescue SystemExit => e
exit exit
rescue Exception => e rescue Exception => e