Skip to content

Commit

Permalink
nested pry, seems to create an anonymous object e.g pry (wait for new…
Browse files Browse the repository at this point in the history
… repl) then pry -- self changes!. Also exit_program seems broken!
  • Loading branch information
banister committed Dec 15, 2010
1 parent 1471507 commit a31d9e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
33 changes: 18 additions & 15 deletions lib/pry.rb
Expand Up @@ -106,6 +106,8 @@ def re(target=TOPLEVEL_BINDING)
target = binding_for(target)
Pry.last_result = target.eval r(target)
target.eval("_ = Pry.last_result")
rescue SystemExit => e
exit
rescue Exception => e
e
end
Expand Down Expand Up @@ -153,17 +155,15 @@ def eval_string.clear() replace("") end
obj = $~.captures.first
target.eval("#{obj}.pry")
eval_string.clear
when /^show_method\s*(\w*)/
when /^show_method\s*(.+)/
meth_name = ($~.captures).first
file, line = target.eval("method(:#{meth_name}).source_location")
tp = Pry.new.tap { |v| v.input = SourceInput.new(file, line) }
output.show_method tp.r
code = get_method_source(target, meth_name, :method)
output.show_method code
eval_string.clear
when /^show_instance_method\s*(\w*)/
when /^show_instance_method\s*(.+)/
meth_name = ($~.captures).first
file, line = target.eval("instance_method(:#{meth_name}).source_location")
tp = Pry.new.tap { |v| v.input = SourceInput.new(file, line) }
output.show_method tp.r
code = get_method_source(target, meth_name, :instance_method)
output.show_method code
eval_string.clear
when /^jump_to\s*(\d*)/
break_level = ($~.captures).first.to_i
Expand All @@ -183,6 +183,11 @@ def eval_string.clear() replace("") end
end
end

def get_method_source(target, meth_name, kind)
file, line = target.eval("#{kind}(:#{meth_name}).source_location")
Pry.new.tap { |v| v.input = SourceInput.new(file, line) }.r
end

def prompt(eval_string, target, nest)
target_self = target.eval('self')

Expand All @@ -198,14 +203,12 @@ def valid_expression?(code)

begin
test_bed.eval(code)
rescue Exception => e
case e
when SyntaxError
case e.message
when /(parse|syntax) error.*?\$end/i, /unterminated/i
return false
end
rescue SyntaxError => e
case e.message
when /(parse|syntax) error.*?\$end/i, /unterminated/i
return false
end
rescue Exception
end
true
end
Expand Down
2 changes: 2 additions & 0 deletions lib/pry/input.rb
Expand Up @@ -2,6 +2,8 @@

class Pry
class Input
trap('INT') { exit }

def read(prompt)
Readline.readline(prompt, true)
end
Expand Down

0 comments on commit a31d9e3

Please sign in to comment.