aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorutilum <oz@utilum.com>2016-12-21 17:41:36 +0100
committerutilum <oz@utilum.com>2016-12-21 17:50:14 +0100
commit83d3b0dbf17582401eb549c4a30f03ecbbfd1a88 (patch)
treebd80970beca75f714c1cad7dbf64027956eedfe6 /activesupport
parentcb029207e19f511cb7b32c0819acb10dbaeb1198 (diff)
downloadrails-83d3b0dbf17582401eb549c4a30f03ecbbfd1a88.tar.gz
rails-83d3b0dbf17582401eb549c4a30f03ecbbfd1a88.tar.bz2
rails-83d3b0dbf17582401eb549c4a30f03ecbbfd1a88.zip
Fix Complex and Rational are duplicable?
See [this test](https://gist.github.com/utilum/78918f1b64f8b61ee732cb266db7c43a).
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md5
-rw-r--r--activesupport/lib/active_support/core_ext/object/duplicable.rb20
-rw-r--r--activesupport/test/core_ext/object/duplicable_test.rb4
3 files changed, 27 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 2a5c8deb11..873a39dbf6 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -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+.
diff --git a/activesupport/lib/active_support/core_ext/object/duplicable.rb b/activesupport/lib/active_support/core_ext/object/duplicable.rb
index ebe31b38ca..c671d34673 100644
--- a/activesupport/lib/active_support/core_ext/object/duplicable.rb
+++ b/activesupport/lib/active_support/core_ext/object/duplicable.rb
@@ -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
diff --git a/activesupport/test/core_ext/object/duplicable_test.rb b/activesupport/test/core_ext/object/duplicable_test.rb
index c2a1e68f57..f78a5f8496 100644
--- a/activesupport/test/core_ext/object/duplicable_test.rb
+++ b/activesupport/test/core_ext/object/duplicable_test.rb
@@ -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