Permalink
Browse files

cleaned up the code a bit. also as a result doesn't use closures (I t…

…hink that

technically makes it use less memory, in theory)
  • Loading branch information...
1 parent c269557 commit 9e97a2c060bb13c1737a5b978e42bf9eac84790c @archit committed Aug 25, 2008
Showing with 6 additions and 5 deletions.
  1. +6 −5 lib/restarts.rb
View
@@ -18,12 +18,13 @@ def raise_with_restarts(condition)
restart = callcc do |cc|
# Have the continuation object accessible via the #restart method.
# FIXME: check for pre defined methods by the name "restart".
- (class <<condition; self; end).class_eval do
- define_method(:restart) do |*id|
- if id.empty?
- return cc
+ condition.instance_variable_set(:@cc, cc)
+ condition.instance_eval do
+ def restart(id=nil)
+ if id.nil?
+ return @cc
else
- return cc.call(id[0])
+ return @cc.call(id[0])
end
end
end

0 comments on commit 9e97a2c

Please sign in to comment.