From c831f67d8b8319076b53836b2c22b9a48973b636 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Wed, 8 Oct 2014 14:08:40 +0200 Subject: [PATCH] Remove Proc#bind from Rails 3.2 --- actionmailer/lib/action_mailer/base.rb | 3 +-- activesupport/lib/active_support/core_ext/proc.rb | 14 -------------- activesupport/lib/active_support/rescuable.rb | 7 +++++-- activesupport/test/core_ext/proc_test.rb | 12 ------------ 4 files changed, 6 insertions(+), 30 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/proc.rb delete mode 100644 activesupport/test/core_ext/proc_test.rb diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 9e2f640915..92a750b870 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -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 diff --git a/activesupport/lib/active_support/core_ext/proc.rb b/activesupport/lib/active_support/core_ext/proc.rb deleted file mode 100644 index 94bb5fb0cb..0000000000 --- a/activesupport/lib/active_support/core_ext/proc.rb +++ /dev/null @@ -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 diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb index 0f4a06468a..d5eb48bf8b 100644 --- a/activesupport/lib/active_support/rescuable.rb +++ b/activesupport/lib/active_support/rescuable.rb @@ -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 diff --git a/activesupport/test/core_ext/proc_test.rb b/activesupport/test/core_ext/proc_test.rb deleted file mode 100644 index dc7b2c957d..0000000000 --- a/activesupport/test/core_ext/proc_test.rb +++ /dev/null @@ -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