From 10c52a17e724bb6a504b6a91a2421df353ae0360 Mon Sep 17 00:00:00 2001 From: Jason Willems Date: Sun, 24 Jul 2016 00:50:20 -0700 Subject: [PATCH 1/2] Add ceiling alias for ceil for Numeric, Integer, Float, and BigDecimal --- ext/bigdecimal/bigdecimal.c | 1 + numeric.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index b1c887c..445a884 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -3312,6 +3312,7 @@ Init_bigdecimal(void) rb_define_method(rb_cBigDecimal, "frac", BigDecimal_frac, 0); rb_define_method(rb_cBigDecimal, "floor", BigDecimal_floor, -1); rb_define_method(rb_cBigDecimal, "ceil", BigDecimal_ceil, -1); + rb_define_alias(rb_cBigDecimal, "ceiling", "ceil"); rb_define_method(rb_cBigDecimal, "power", BigDecimal_power, -1); rb_define_method(rb_cBigDecimal, "**", BigDecimal_power_op, 1); rb_define_method(rb_cBigDecimal, "<=>", BigDecimal_comp, 1); diff --git a/numeric.c b/numeric.c index 0c0ca82..33b3fe9 100644 --- a/numeric.c +++ b/numeric.c @@ -5035,6 +5035,7 @@ Init_Numeric(void) rb_define_method(rb_cNumeric, "floor", num_floor, -1); rb_define_method(rb_cNumeric, "ceil", num_ceil, -1); + rb_define_alias(rb_cNumeric, "ceiling", "ceil"); rb_define_method(rb_cNumeric, "round", num_round, -1); rb_define_method(rb_cNumeric, "truncate", num_truncate, -1); rb_define_method(rb_cNumeric, "step", num_step, -1); @@ -5063,6 +5064,7 @@ Init_Numeric(void) rb_define_method(rb_cInteger, "to_f", int_to_f, 0); rb_define_method(rb_cInteger, "floor", int_floor, -1); rb_define_method(rb_cInteger, "ceil", int_ceil, -1); + rb_define_alias(rb_cInteger, "ceiling", "ceil"); rb_define_method(rb_cInteger, "truncate", int_truncate, -1); rb_define_method(rb_cInteger, "round", int_round, -1); rb_define_method(rb_cInteger, "<=>", int_cmp, 1); @@ -5240,6 +5242,7 @@ Init_Numeric(void) rb_define_method(rb_cFloat, "to_int", flo_to_i, 0); rb_define_method(rb_cFloat, "floor", flo_floor, -1); rb_define_method(rb_cFloat, "ceil", flo_ceil, -1); + rb_define_alias(rb_cFloat, "ceiling", "ceil"); rb_define_method(rb_cFloat, "round", flo_round, -1); rb_define_method(rb_cFloat, "truncate", flo_truncate, -1); -- 2.7.4 (Apple Git-66) From 3246be2c3c74d49bf519b160cdf8c7215cf02a2c Mon Sep 17 00:00:00 2001 From: Jason Willems Date: Sun, 24 Jul 2016 23:42:37 -0700 Subject: [PATCH 2/2] Document alias in code --- numeric.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/numeric.c b/numeric.c index 33b3fe9..8e4f2ab 100644 --- a/numeric.c +++ b/numeric.c @@ -1805,7 +1805,8 @@ flo_floor(int argc, VALUE *argv, VALUE num) /* * call-seq: - * float.ceil([ndigits]) -> integer or float + * float.ceil([ndigits]) -> integer or float + * float.ceiling([ndigits]) -> integer or float * * Returns the smallest number greater than or equal to +float+ in decimal * digits (default 0 digits). @@ -1831,6 +1832,8 @@ flo_floor(int argc, VALUE *argv, VALUE num) * 34567.89.ceil(1) #=> 34567.9 * 34567.89.ceil(2) #=> 34567.89 * 34567.89.ceil(3) #=> 34567.89 + * + * Float#ceiling is an alias of Float#ceil. */ static VALUE @@ -2173,7 +2176,8 @@ num_floor(int argc, VALUE *argv, VALUE num) /* * call-seq: - * num.ceil([ndigits]) -> integer or float + * num.ceil([ndigits]) -> integer or float + * num.ceiling([ndigits]) -> integer or float * * Returns the smallest possible Integer that is greater than or equal to * +num+. @@ -2185,6 +2189,8 @@ num_floor(int argc, VALUE *argv, VALUE num) * 1.2.ceil #=> 2 * (-1.2).ceil #=> -1 * (-1.0).ceil #=> -1 + * + * Numeric#ceiling is an alias of Numeric#ceil. */ static VALUE @@ -4831,7 +4837,8 @@ int_floor(int argc, VALUE* argv, VALUE num) /* * Document-method: Integer#ceil * call-seq: - * int.ceil([ndigits]) -> integer or float + * int.ceil([ndigits]) -> integer or float + * int.ceiling([ndigits]) -> integer or float * * Returns the smallest number than or equal to +int+ in decimal * digits (default 0 digits). @@ -4842,6 +4849,8 @@ int_floor(int argc, VALUE* argv, VALUE num) * 1.ceil #=> 1 * 1.ceil(2) #=> 1.0 * 15.ceil(-1) #=> 20 + * + * Integer#ceiling is an alias of Integer#ceil. */ static VALUE -- 2.7.4 (Apple Git-66)