def synchronize(*methods)
options = methods.extract_options!
unless options.is_a?(Hash) && with = options[:with]
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.each do |method|
aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
if method_defined?("#{aliased_method}_without_synchronization#{punctuation}")
raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported."
end
module_eval("def \#{aliased_method}_with_synchronization\#{punctuation}(*args, &block) # def expire_with_synchronization(*args, &block)\n\#{with}.synchronize do # @@lock.synchronize do\n\#{aliased_method}_without_synchronization\#{punctuation}(*args, &block) # expire_without_synchronization(*args, &block)\nend # end\nend # end\n", __FILE__, __LINE__ + 1)
alias_method_chain method, :synchronization
end
end