Skip to content
Browse files

Ruby 1.9 compat: use method_defined? instead of instance_methods.incl…

…ude? Don't encourage args abuse by flattening.
  • Loading branch information...
1 parent 227ee2e commit 15b1b2b778ce18ff23737b3a0674780d22605fdf @jeremy jeremy committed
Showing with 6 additions and 3 deletions.
  1. +6 −3 activesupport/lib/active_support/core_ext/module/synchronization.rb
9 activesupport/lib/active_support/core_ext/module/synchronization.rb
@@ -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)."
- 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."
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)
alias_method_chain method, :synchronization

3 comments on commit 15b1b2b


Shouldn’t the check for preexisting alias_method_chain’d methods be performed by alias_method_chain itself? That would prevent infinite recursions in case the same alias_method_chain call is evaluated more than once (double require’s or load’s).

Ruby on Rails member


Ruby on Rails member

We had this in an earlier commit but it hosed migrations. Odds are it was simply mis-detecting whether the method existed and falling back on the super classes. If you want to take a look it’s in the logs here somewhere.

Please sign in to comment.
Something went wrong with that request. Please try again.