From 71476313e0f94b7887bcb7aad3956c0d62505f4c Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 11 Jul 2019 17:39:19 +0200 Subject: [PATCH] Implement UnboundMethod#duplicable? --- .../lib/active_support/core_ext/object/duplicable.rb | 11 ++++++++++- activesupport/test/core_ext/object/duplicable_test.rb | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/object/duplicable.rb b/activesupport/lib/active_support/core_ext/object/duplicable.rb index 265bb7bf48..3ebcdca02b 100644 --- a/activesupport/lib/active_support/core_ext/object/duplicable.rb +++ b/activesupport/lib/active_support/core_ext/object/duplicable.rb @@ -1,4 +1,3 @@ - # frozen_string_literal: true #-- @@ -38,3 +37,13 @@ class Method false end end + +class UnboundMethod + # Unbound methods are not duplicable: + # + # method(:puts).unbind.duplicable? # => false + # method(:puts).unbind.dup # => TypeError: allocator undefined for UnboundMethod + def duplicable? + false + end +end diff --git a/activesupport/test/core_ext/object/duplicable_test.rb b/activesupport/test/core_ext/object/duplicable_test.rb index c9af2cb624..a577c30c40 100644 --- a/activesupport/test/core_ext/object/duplicable_test.rb +++ b/activesupport/test/core_ext/object/duplicable_test.rb @@ -6,7 +6,7 @@ require "active_support/core_ext/object/duplicable" require "active_support/core_ext/numeric/time" class DuplicableTest < ActiveSupport::TestCase - RAISE_DUP = [method(:puts)] + RAISE_DUP = [method(:puts), method(:puts).unbind] ALLOW_DUP = ["1", "symbol_from_string".to_sym, Object.new, /foo/, [], {}, Time.now, Class.new, Module.new, BigDecimal("4.56"), nil, false, true, 1, 2.3, Complex(1), Rational(1)] def test_duplicable