提交 4d6e178f 编写于 作者: E Emilio Tagua

Remove method if exists, avoid calling Array#first so many times.

上级 da8f9ca4
......@@ -19,9 +19,11 @@ class Callbacks
# 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册