1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Implement UnboundMethod#duplicable?

This commit is contained in:
Jean Boussier 2019-07-11 17:39:19 +02:00
parent 59f450500c
commit 71476313e0
2 changed files with 11 additions and 2 deletions

View file

@ -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

View file

@ -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