Remove Proc#bind from Rails 3.2

This commit is contained in:
Dirkjan Bussink
2014-10-08 14:08:40 +02:00
parent b6f150c40c
commit c831f67d8b
4 changed files with 6 additions and 30 deletions

View File

@@ -2,7 +2,6 @@ require 'mail'
require 'action_mailer/collector'
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/proc'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/module/anonymous'
@@ -627,7 +626,7 @@ module ActionMailer #:nodoc:
# Call all the procs (if any)
default_values = self.class.default.merge(self.class.default) do |k,v|
v.respond_to?(:call) ? v.bind(self).call : v
v.respond_to?(:call) ? instance_eval(&v) : v
end
# Handle defaults

View File

@@ -1,14 +0,0 @@
require "active_support/core_ext/kernel/singleton_class"
class Proc #:nodoc:
def bind(object)
block, time = self, Time.now
object.class_eval do
method_name = "__bind_#{time.to_i}_#{time.usec}"
define_method(method_name, &block)
method = instance_method(method_name)
remove_method(method_name)
method
end.bind(object)
end
end

View File

@@ -1,6 +1,5 @@
require 'active_support/concern'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/proc'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/array/extract_options'
@@ -108,7 +107,11 @@ module ActiveSupport
when Symbol
method(rescuer)
when Proc
rescuer.bind(self)
if rescuer.arity == 0
Proc.new { instance_exec(&rescuer) }
else
Proc.new { |_exception| instance_exec(_exception, &rescuer) }
end
end
end
end

View File

@@ -1,12 +0,0 @@
require 'abstract_unit'
require 'active_support/core_ext/proc'
class ProcTests < Test::Unit::TestCase
def test_bind_returns_method_with_changed_self
block = Proc.new { self }
assert_equal self, block.call
bound_block = block.bind("hello")
assert_not_equal block, bound_block
assert_equal "hello", bound_block.call
end
end