mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Define Singleton#duplicable? and return false
This commit is contained in:
parent
b453bff351
commit
a65b8a00cb
2 changed files with 12 additions and 1 deletions
|
@ -47,3 +47,14 @@ class UnboundMethod
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
require "singleton"
|
||||
|
||||
module Singleton
|
||||
# Singleton instances are not duplicable:
|
||||
#
|
||||
# Class.new.include(Singleton).instance.dup # TypeError (can't dup instance of singleton
|
||||
def duplicable?
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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), method(:puts).unbind]
|
||||
RAISE_DUP = [method(:puts), method(:puts).unbind, Class.new.include(Singleton).instance]
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue