diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-03-23 13:48:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-23 13:48:02 +0100 |
commit | 307fd7407f868095e107bd9af66b949b0ee40c20 (patch) | |
tree | 70836d9618e1bbc37d0edbf5d8f5c99c23337082 /activesupport | |
parent | 2a504ebf31640e6f9dda77b84367c87f5729ad8e (diff) | |
parent | 7045e03dee2cda9af65bc8e51bddab79599f44cd (diff) | |
download | rails-307fd7407f868095e107bd9af66b949b0ee40c20.tar.gz rails-307fd7407f868095e107bd9af66b949b0ee40c20.tar.bz2 rails-307fd7407f868095e107bd9af66b949b0ee40c20.zip |
Merge pull request #28544 from vipulnsward/fix-on-ruby-master
Fix duplicable? for Rational and Complex on ruby master, since they are now duplicable
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/duplicable.rb | 34 | ||||
-rw-r--r-- | activesupport/test/core_ext/object/duplicable_test.rb | 5 |
2 files changed, 26 insertions, 13 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/duplicable.rb b/activesupport/lib/active_support/core_ext/object/duplicable.rb index ea81df2bd8..c27fd4f792 100644 --- a/activesupport/lib/active_support/core_ext/object/duplicable.rb +++ b/activesupport/lib/active_support/core_ext/object/duplicable.rb @@ -124,21 +124,31 @@ class Method end class Complex - # Complexes are not duplicable: - # - # Complex(1).duplicable? # => false - # Complex(1).dup # => TypeError: can't copy Complex - def duplicable? - false + begin + Complex(1).dup + rescue TypeError + + # Complexes are not duplicable for RUBY_VERSION < 2.5.0: + # + # Complex(1).duplicable? # => false + # Complex(1).dup # => TypeError: can't copy Complex + def duplicable? + false + end end end class Rational - # Rationals are not duplicable: - # - # Rational(1).duplicable? # => false - # Rational(1).dup # => TypeError: can't copy Rational - def duplicable? - false + begin + Rational(1).dup + rescue TypeError + + # Rationals are not duplicable for RUBY_VERSION < 2.5.0: + # + # Rational(1).duplicable? # => false + # Rational(1).dup # => TypeError: can't copy Rational + def duplicable? + false + end end end diff --git a/activesupport/test/core_ext/object/duplicable_test.rb b/activesupport/test/core_ext/object/duplicable_test.rb index e6f3c8aef2..68b0129980 100644 --- a/activesupport/test/core_ext/object/duplicable_test.rb +++ b/activesupport/test/core_ext/object/duplicable_test.rb @@ -4,7 +4,10 @@ require "active_support/core_ext/object/duplicable" require "active_support/core_ext/numeric/time" class DuplicableTest < ActiveSupport::TestCase - if RUBY_VERSION >= "2.4.1" + if RUBY_VERSION >= "2.5.0" + RAISE_DUP = [method(:puts)] + ALLOW_DUP = ["1", "symbol_from_string".to_sym, Object.new, /foo/, [], {}, Time.now, Class.new, Module.new, BigDecimal.new("4.56"), nil, false, true, 1, 2.3, Complex(1), Rational(1)] + elsif RUBY_VERSION >= "2.4.1" RAISE_DUP = [method(:puts), Complex(1), Rational(1)] ALLOW_DUP = ["1", "symbol_from_string".to_sym, Object.new, /foo/, [], {}, Time.now, Class.new, Module.new, BigDecimal.new("4.56"), nil, false, true, 1, 2.3] elsif RUBY_VERSION >= "2.4.0" # Due to 2.4.0 bug. This elsif cannot be removed unless we drop 2.4.0 support... |