Permalink
Browse files

Remove BigDecimal.new

fix #89
  • Loading branch information...
mrkn committed Nov 20, 2018
1 parent 05d1554 commit d73eca27de842928dd7f4480d7d6e435f50c9bc2
Showing with 35 additions and 51 deletions.
  1. +32 −40 ext/bigdecimal/bigdecimal.c
  2. +3 −11 test/bigdecimal/test_bigdecimal.rb
@@ -2569,44 +2569,6 @@ BigDecimal_s_allocate(VALUE klass)

static Real *BigDecimal_new(int argc, VALUE *argv);

/* call-seq:
* new(initial, digits)
*
* Create a new BigDecimal object.
*
* initial:: The initial value, as an Integer, a Float, a Rational,
* a BigDecimal, or a String.
*
* If it is a String, spaces are ignored and unrecognized characters
* terminate the value.
*
* digits:: The number of significant digits, as an Integer. If omitted or 0,
* the number of significant digits is determined from the initial
* value.
*
* The actual number of significant digits used in computation is usually
* larger than the specified number.
*
* ==== Exceptions
*
* TypeError:: If the +initial+ type is neither Integer, Float,
* Rational, nor BigDecimal, this exception is raised.
*
* TypeError:: If the +digits+ is not an Integer, this exception is raised.
*
* ArgumentError:: If +initial+ is a Float, and the +digits+ is larger than
* Float::DIG + 1, this exception is raised.
*
* ArgumentError:: If the +initial+ is a Float or Rational, and the +digits+
* value is omitted, this exception is raised.
*/
static VALUE
BigDecimal_s_new(int argc, VALUE *argv, VALUE self)
{
rb_warning("BigDecimal.new is deprecated; use Kernel.BigDecimal method instead.");
return rb_call_super(argc, argv);
}

static VALUE
BigDecimal_initialize(int argc, VALUE *argv, VALUE self)
{
@@ -2704,7 +2666,37 @@ BigDecimal_new(int argc, VALUE *argv)
return VpAlloc(mf, RSTRING_PTR(iniValue));
}

/* See also BigDecimal.new */
/* call-seq:
* BigDecimal(initial, digits)
*
* Create a new BigDecimal object.
*
* initial:: The initial value, as an Integer, a Float, a Rational,
* a BigDecimal, or a String.
*
* If it is a String, spaces are ignored and unrecognized characters
* terminate the value.
*
* digits:: The number of significant digits, as an Integer. If omitted or 0,
* the number of significant digits is determined from the initial
* value.
*
* The actual number of significant digits used in computation is usually
* larger than the specified number.
*
* ==== Exceptions
*
* TypeError:: If the +initial+ type is neither Integer, Float,
* Rational, nor BigDecimal, this exception is raised.
*
* TypeError:: If the +digits+ is not an Integer, this exception is raised.
*
* ArgumentError:: If +initial+ is a Float, and the +digits+ is larger than
* Float::DIG + 1, this exception is raised.
*
* ArgumentError:: If the +initial+ is a Float or Rational, and the +digits+
* value is omitted, this exception is raised.
*/
static VALUE
BigDecimal_global_new(int argc, VALUE *argv, VALUE self)
{
@@ -3285,7 +3277,7 @@ Init_bigdecimal(void)
rb_define_global_function("BigDecimal", BigDecimal_global_new, -1);

/* Class methods */
rb_define_singleton_method(rb_cBigDecimal, "new", BigDecimal_s_new, -1);
rb_undef_method(CLASS_OF(rb_cBigDecimal), "new");
rb_define_singleton_method(rb_cBigDecimal, "mode", BigDecimal_mode, -1);
rb_define_singleton_method(rb_cBigDecimal, "limit", BigDecimal_limit, -1);
rb_define_singleton_method(rb_cBigDecimal, "double_fig", BigDecimal_double_fig, 0);
@@ -136,9 +136,7 @@ def test_s_ver
end

def test_s_new
assert_warning(/BigDecimal.new is deprecated/) do
BigDecimal.new("1")
end
assert_raise(NoMethodError, /undefined method `new`/) { BigDecimal.new("1") }
end

def test_new
@@ -1801,14 +1799,8 @@ def test_dup
end

def test_dup_subclass
assert_warning(/BigDecimal\.new is deprecated/) do
c = Class.new(BigDecimal)
x = c.new(1)
y = x.dup
assert_same(x, y)
assert_equal(1, y)
assert_kind_of(c, y)
end
c = Class.new(BigDecimal)
assert_raise(NoMethodError, /undefined method `new`/) { c.new(1) }
end

def test_to_d

0 comments on commit d73eca2

Please sign in to comment.