aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/synchronization.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-09-06 18:45:52 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-09-06 18:45:52 -0700
commit15b1b2b778ce18ff23737b3a0674780d22605fdf (patch)
treee6353054979fed0c886cea51ae75dce1b4eb7828 /activesupport/lib/active_support/core_ext/module/synchronization.rb
parent227ee2ecb46f1609938a83ed82abde1a45ebe2eb (diff)
downloadrails-15b1b2b778ce18ff23737b3a0674780d22605fdf.tar.gz
rails-15b1b2b778ce18ff23737b3a0674780d22605fdf.tar.bz2
rails-15b1b2b778ce18ff23737b3a0674780d22605fdf.zip
Ruby 1.9 compat: use method_defined? instead of instance_methods.include? Don't encourage args abuse by flattening.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/synchronization.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/module/synchronization.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/synchronization.rb b/activesupport/lib/active_support/core_ext/module/synchronization.rb
index 6253594dfa..251606024e 100644
--- a/activesupport/lib/active_support/core_ext/module/synchronization.rb
+++ b/activesupport/lib/active_support/core_ext/module/synchronization.rb
@@ -18,11 +18,13 @@ class Module
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 @@ class Module
end
end
EOS
+
alias_method_chain method, :synchronization
end
end
-end \ No newline at end of file
+end