Skip to content

Commit 8632a53

Browse files
authored
Merge pull request rails#41095 from Shopify/singleton-duplicable
Define Singleton#duplicable? and return false
2 parents b453bff + a65b8a0 commit 8632a53

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

activesupport/lib/active_support/core_ext/object/duplicable.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ def duplicable?
4747
false
4848
end
4949
end
50+
51+
require "singleton"
52+
53+
module Singleton
54+
# Singleton instances are not duplicable:
55+
#
56+
# Class.new.include(Singleton).instance.dup # TypeError (can't dup instance of singleton
57+
def duplicable?
58+
false
59+
end
60+
end

activesupport/test/core_ext/object/duplicable_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
require "active_support/core_ext/numeric/time"
77

88
class DuplicableTest < ActiveSupport::TestCase
9-
RAISE_DUP = [method(:puts), method(:puts).unbind]
9+
RAISE_DUP = [method(:puts), method(:puts).unbind, Class.new.include(Singleton).instance]
1010
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)]
1111

1212
def test_duplicable

0 commit comments

Comments
 (0)