提交 15b1b2b7 编写于 作者: J Jeremy Kemper

Ruby 1.9 compat: use method_defined? instead of instance_methods.include? ...

Ruby 1.9 compat: use method_defined? instead of instance_methods.include?  Don't encourage args abuse by flattening.
上级 227ee2ec
......@@ -18,11 +18,13 @@ def synchronize(*methods)
raise ArgumentError, "Synchronization needs a mutex. Supply an options hash with a :with key as the last argument (e.g. synchronize :hello, :with => :@mutex)."
end
methods.flatten.each do |method|
methods.each do |method|
aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
if instance_methods.include?("#{aliased_method}_without_synchronization#{punctuation}")
if method_defined?("#{aliased_method}_without_synchronization#{punctuation}")
raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported."
end
module_eval(<<-EOS, __FILE__, __LINE__)
def #{aliased_method}_with_synchronization#{punctuation}(*args, &block)
#{with}.synchronize do
......@@ -30,7 +32,8 @@ def #{aliased_method}_with_synchronization#{punctuation}(*args, &block)
end
end
EOS
alias_method_chain method, :synchronization
end
end
end
\ No newline at end of file
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册