Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 15b1b2b778ce18ff23737b3a0674780d22605fdf 1 parent 227ee2e
@jeremy jeremy authored
View
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)."
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
+end

3 comments on commit 15b1b2b

@Roman2K

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).

@josh
Collaborator

PDI

@NZKoz
Owner

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.