Permalink
Browse files

only calculate next_id when we need a new method defined

  • Loading branch information...
tenderlove committed Feb 22, 2013
1 parent b359c5d commit 54f9b7584dc145963e2b9bffb0963c9f45ff8528
Showing with 2 additions and 1 deletion.
  1. +2 −1 activesupport/lib/active_support/callbacks.rb
@@ -255,7 +255,6 @@ def recompile_options!
# a method is created that calls the before_foo method
# on the object.
def _compile_filter(filter)
- method_name = "_callback_#{@kind}_#{next_id}"
case filter
when Array
filter.map {|f| _compile_filter(f)}
@@ -264,11 +263,13 @@ def _compile_filter(filter)
when String
"(#{filter})"
when Proc
+ method_name = "_callback_#{@kind}_#{next_id}"
@klass.send(:define_method, method_name, &filter)
return method_name if filter.arity <= 0
method_name << (filter.arity == 1 ? "(self)" : " self, Proc.new ")
else
+ method_name = "_callback_#{@kind}_#{next_id}"
@klass.send(:define_method, "#{method_name}_object") { filter }
_normalize_legacy_filter(kind, filter)

0 comments on commit 54f9b75

Please sign in to comment.