Permalink
Browse files

use a singleton end node

  • Loading branch information...
1 parent d2c0571 commit 73aefee3f23f54786c69f1bafa5b1f0b5aee8398 @tenderlove tenderlove committed May 13, 2013
Showing with 10 additions and 5 deletions.
  1. +10 −5 activesupport/lib/active_support/callbacks.rb
View
15 activesupport/lib/active_support/callbacks.rb
@@ -96,6 +96,15 @@ def halted_callback_hook(filter)
module Filters
Environment = Struct.new(:target, :halted, :value, :run_block)
+
+ class End
+ def call(env)
+ block = env.run_block
+ env.value = !env.halted && (!block || block.call)
+ env
+ end
+ end
+ ENDING = End.new
end
class Callback #:nodoc:#
@@ -361,11 +370,7 @@ def initialize_copy(other)
def compile
return @callbacks if @callbacks
- @callbacks = lambda { |env|
- block = env.run_block
- env.value = !env.halted && (!block || block.call)
- env
- }
+ @callbacks = Filters::ENDING
@chain.reverse_each do |callback|
@callbacks = callback.apply(@callbacks)
end

0 comments on commit 73aefee

Please sign in to comment.