提交 83d3b0db 编写于 作者: U utilum

Fix Complex and Rational are duplicable?

See [this test](https://gist.github.com/utilum/78918f1b64f8b61ee732cb266db7c43a).
上级 cb029207
* Change return value of `Rational#duplicable?`, `ComplexClass#duplicable?`
to false.
*utilum*
* Change return value of `NilClass#duplicable?`, `FalseClass#duplicable?`,
`TrueClass#duplicable?`, `Symbol#duplicable?` and `Numeric#duplicable?`
to true with Ruby 2.4+. These classes can dup with Ruby 2.4+.
......
......@@ -121,3 +121,23 @@ def duplicable?
false
end
end
class Complex
# Complexes are not duplicable:
#
# Complex(1).duplicable? # => false
# Complex(1).dup # => TypeError: can't copy Complex
def duplicable?
false
end
end
class Rational
# Rationals are not duplicable:
#
# Rational(1).duplicable? # => false
# Rational(1).dup # => TypeError: can't copy Rational
def duplicable?
false
end
end
......@@ -5,10 +5,10 @@
class DuplicableTest < ActiveSupport::TestCase
if RUBY_VERSION >= "2.4.0"
RAISE_DUP = [method(:puts)]
RAISE_DUP = [method(:puts), Complex(1), Rational(1)]
ALLOW_DUP = ["1", Object.new, /foo/, [], {}, Time.now, Class.new, Module.new, BigDecimal.new("4.56"), nil, false, true, :symbol, 1, 2.3]
else
RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, method(:puts)]
RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, method(:puts), Complex(1), Rational(1)]
ALLOW_DUP = ["1", Object.new, /foo/, [], {}, Time.now, Class.new, Module.new, BigDecimal.new("4.56")]
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册