diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-22 02:02:11 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-22 02:02:11 +0000 |
commit | 31ef3124a9db534abcc3e323f5d3cb696eda3bf5 (patch) | |
tree | b1c6f0327fb570019586b007bcce785d6c495b99 /numeric.c | |
parent | 4096f39dcf41628d2248ac2a7dcbd9f45751946a (diff) | |
download | ruby-31ef3124a9db534abcc3e323f5d3cb696eda3bf5.tar.gz |
numeric.c: Numeric#clone and #dup
* numeric.c (num_clone, num_dup): no longer raises TypeError,
returns the receiver instead as well as Integer and Float.
[ruby-core:79636] [Bug #13237]
* object.c (rb_immutable_obj_clone): immutable object clone with
freeze optional keyword argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 33 |
1 files changed, 27 insertions, 6 deletions
@@ -552,18 +552,38 @@ num_sadded(VALUE x, VALUE name) UNREACHABLE; } +#if 0 /* - * Numerics are immutable values, which should not be copied. + * call-seq: + * num.clone(freeze: true) -> num * - * Any attempt to use this method on a Numeric will raise a TypeError. + * Returns the receiver. + * _freeze_ cannot be +false+. */ static VALUE -num_init_copy(VALUE x, VALUE y) +num_clone(int argc, VALUE *argv, VALUE x) { - rb_raise(rb_eTypeError, "can't copy %"PRIsVALUE, rb_obj_class(x)); + return rb_immutable_obj_clone(argc, argv, x); +} +#else +# define num_clone rb_immutable_obj_clone +#endif - UNREACHABLE; +#if 0 +/* + * call-seq: + * num.dup -> num + * + * Returns the receiver. + */ +static VALUE +num_dup(VALUE x) +{ + return x; } +#else +# define num_dup num_uplus +#endif /* * call-seq: @@ -5222,8 +5242,9 @@ Init_Numeric(void) rb_define_method(rb_cNumeric, "singleton_method_added", num_sadded, 1); rb_include_module(rb_cNumeric, rb_mComparable); - rb_define_method(rb_cNumeric, "initialize_copy", num_init_copy, 1); rb_define_method(rb_cNumeric, "coerce", num_coerce, 1); + rb_define_method(rb_cNumeric, "clone", num_clone, -1); + rb_define_method(rb_cNumeric, "dup", num_dup, 0); rb_define_method(rb_cNumeric, "i", num_imaginary, 0); rb_define_method(rb_cNumeric, "+@", num_uplus, 0); |