mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix Complex and Rational are duplicable?
See [this test](https://gist.github.com/utilum/78918f1b64f8b61ee732cb266db7c43a).
This commit is contained in:
parent
cb029207e1
commit
83d3b0dbf1
3 changed files with 27 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
* 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 @@ class Method
|
|||
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 @@ require "active_support/core_ext/numeric/time"
|
|||
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue