diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-28 16:31:21 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-09-28 16:31:21 -0300 |
commit | 4d6e178f888c8287eb59e14bd9ecb77b4d71455b (patch) | |
tree | 4c1e0664c67ab50a14196d86c59c4e99f1812152 /actionpack/lib/action_dispatch/middleware/callbacks.rb | |
parent | da8f9ca4329499fc9cc9c3f999a9d6eecdc801d3 (diff) | |
download | rails-4d6e178f888c8287eb59e14bd9ecb77b4d71455b.tar.gz rails-4d6e178f888c8287eb59e14bd9ecb77b4d71455b.tar.bz2 rails-4d6e178f888c8287eb59e14bd9ecb77b4d71455b.zip |
Remove method if exists, avoid calling Array#first so many times.
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/callbacks.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/callbacks.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/callbacks.rb b/actionpack/lib/action_dispatch/middleware/callbacks.rb index e4ae480bfb..0bb950d1cc 100644 --- a/actionpack/lib/action_dispatch/middleware/callbacks.rb +++ b/actionpack/lib/action_dispatch/middleware/callbacks.rb @@ -19,9 +19,11 @@ module ActionDispatch # replace the existing callback. Passing an identifier is a suggested # practice if the code adding a preparation block may be reloaded. def self.to_prepare(*args, &block) - if args.first.is_a?(Symbol) && block_given? - define_method :"__#{args.first}", &block - set_callback(:prepare, :"__#{args.first}") + first_arg = args.first + if first_arg.is_a?(Symbol) && block_given? + remove_method :"__#{first_arg}" if method_defined?(:"__#{first_arg}") + define_method :"__#{first_arg}", &block + set_callback(:prepare, :"__#{first_arg}") else set_callback(:prepare, *args, &block) end |