diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-10-08 15:23:46 -0700 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-06 01:15:45 +0900 |
commit | ceb9d516c6d17b0619cf53dfba7cb7b29fe073e4 (patch) | |
tree | d888fc8896a20b212eb7bd96cf3962db488baafe | |
parent | d69510b6cda4024237de8f5766d85397abd5e434 (diff) |
[ruby/bigdecimal] Undef BigDecimal#initialize_copy
Both BigDecimal#clone and BigDecimal#dup return self, there is no
reason to have initialize_copy exposed as a Ruby method.
The same is true for initialize_clone and initialize_dup.
https://github.com/ruby/bigdecimal/commit/aaf237fa9e
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3295
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 4 | ||||
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index c442335a0a..23851eea58 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -3451,7 +3451,9 @@ Init_bigdecimal(void) /* instance methods */ - rb_define_method(rb_cBigDecimal, "initialize_copy", BigDecimal_initialize_copy, 1); + rb_undef_method(rb_cBigDecimal, "initialize_copy"); + rb_undef_method(rb_cBigDecimal, "initialize_clone"); + rb_undef_method(rb_cBigDecimal, "initialize_dup"); rb_define_method(rb_cBigDecimal, "precs", BigDecimal_prec, 0); rb_define_method(rb_cBigDecimal, "add", BigDecimal_add2, 2); diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 4598936b9a..6928834907 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -1876,6 +1876,12 @@ class TestBigDecimal < Test::Unit::TestCase EOS end + def test_no_initialize_copy + assert_equal(false, BigDecimal(1).respond_to?(:initialize_copy, true)) + assert_equal(false, BigDecimal(1).respond_to?(:initialize_dup, true)) + assert_equal(false, BigDecimal(1).respond_to?(:initialize_clone, true)) + end + def assert_no_memory_leak(code, *rest, **opt) code = "8.times {20_000.times {begin #{code}; rescue NoMemoryError; end}; GC.start}" super(["-rbigdecimal"], |