diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index faa683ff..a0f5cb2e 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -139,11 +139,13 @@ class Pry # edit of local code, eval'd within pry. if !opts.ex? && args.empty? - content = if !eval_string.empty? + content = if opts.t? + "" + elsif eval_string.strip != "" eval_string - elsif !opts.t? - _pry_.input_array.reverse_each.find{ |x| x && x.strip != "" } # No present? in 1.8 - end || "" + else + _pry_.input_array.reverse_each.find{ |x| x && x.strip != "" } || "" + end line = content.lines.count diff --git a/test/test_default_commands/test_introspection.rb b/test/test_default_commands/test_introspection.rb index 78dc426e..beac04cb 100644 --- a/test/test_default_commands/test_introspection.rb +++ b/test/test_default_commands/test_introspection.rb @@ -187,6 +187,11 @@ describe "Pry::DefaultCommands::Introspection" do @contents.should == "\n" end + it "should use a blank file if -t is specified even half-way through an expression" do + mock_pry("def a;", "edit -t") + @contents.should == "\n" + end + it "should position the cursor at the end of the expression" do mock_pry("def a; 2;"," end", "edit") @line.should == 2