Skip to content

Commit aaf237f

Browse files
committed
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.
1 parent 92356ba commit aaf237f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3453,7 +3453,9 @@ Init_bigdecimal(void)
34533453

34543454

34553455
/* instance methods */
3456-
rb_define_method(rb_cBigDecimal, "initialize_copy", BigDecimal_initialize_copy, 1);
3456+
rb_undef_method(rb_cBigDecimal, "initialize_copy");
3457+
rb_undef_method(rb_cBigDecimal, "initialize_clone");
3458+
rb_undef_method(rb_cBigDecimal, "initialize_dup");
34573459
rb_define_method(rb_cBigDecimal, "precs", BigDecimal_prec, 0);
34583460

34593461
rb_define_method(rb_cBigDecimal, "add", BigDecimal_add2, 2);

test/bigdecimal/test_bigdecimal.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,12 @@ def test_bug6406
18741874
EOS
18751875
end
18761876

1877+
def test_no_initialize_copy
1878+
assert_equal(false, BigDecimal(1).respond_to?(:initialize_copy, true))
1879+
assert_equal(false, BigDecimal(1).respond_to?(:initialize_dup, true))
1880+
assert_equal(false, BigDecimal(1).respond_to?(:initialize_clone, true))
1881+
end
1882+
18771883
def assert_no_memory_leak(code, *rest, **opt)
18781884
code = "8.times {20_000.times {begin #{code}; rescue NoMemoryError; end}; GC.start}"
18791885
super(["-rbigdecimal"],

0 commit comments

Comments
 (0)