Skip to content

Commit

Permalink
Instead of using globals for storing the last exception, use the loca…
Browse files Browse the repository at this point in the history
…l vars: e & exception

From: Eloy Duran <eloy.de.enige@gmail.com>

git-svn-id: http://svn.macosforge.org/repository/ruby/DietRB/trunk@4746 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
alloy committed Oct 8, 2010
1 parent 4fa6c1c commit c496f37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/irb/context.rb
Expand Up @@ -19,7 +19,8 @@ def initialize(object, explicit_binding = nil)
@line = 1
clear_buffer

@underscore_assigner = __evaluate__("_ = nil; proc { |val| _ = val }")
@last_result_assigner = __evaluate__("_ = nil; proc { |val| _ = val }")
@exception_assigner = __evaluate__("e = exception = nil; proc { |ex| e = exception = ex }")
end

def __evaluate__(source, file = __FILE__, line = __LINE__)
Expand Down Expand Up @@ -84,11 +85,11 @@ def clear_buffer
end

def store_result(result)
@underscore_assigner.call(result)
@last_result_assigner.call(result)
end

def store_exception(exception)
$e = $EXCEPTION = exception
@exception_assigner.call(exception)
end
end
end
8 changes: 4 additions & 4 deletions spec/context_spec.rb
Expand Up @@ -75,11 +75,11 @@ def o.to_s; "self"; end
}.should_not.raise_error
end

it "assigns the last raised exception to the global variable `$EXCEPTION' / `$e'" do
it "assigns the last raised exception to the variables `exception' / `e'" do
@context.evaluate("DoesNotExist")
$EXCEPTION.class.should == NameError
$EXCEPTION.message.should include('DoesNotExist')
$e.should == $EXCEPTION
@context.__evaluate__("exception").class.should == NameError
@context.__evaluate__("exception").message.should include('DoesNotExist')
@context.__evaluate__("e").should == @context.__evaluate__("exception")
end

it "prints the exception that occurs" do
Expand Down

0 comments on commit c496f37

Please sign in to comment.