From 2e551356a7a6e74ba07283e000ff16f5d1ea6506 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 7 Aug 2019 09:01:33 -0700 Subject: Make Kernel#{Pathname,BigDecimal,Complex} return argument if given correct type This is how Kernel#{Array,String,Float,Integer,Hash,Rational} work. BigDecimal and Complex instances are always frozen, so this should not cause backwards compatibility issues for those. Pathname instances are not frozen, so potentially this could cause backwards compatibility issues by not returning a new object. Based on a patch from Joshua Ballanco, some minor changes by me. Fixes [Bug #7522] --- complex.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'complex.c') diff --git a/complex.c b/complex.c index ec60c00ed6..144a59d533 100644 --- a/complex.c +++ b/complex.c @@ -563,6 +563,9 @@ nucomp_f_complex(int argc, VALUE *argv, VALUE klass) if (!NIL_P(opts)) { raise = rb_opts_exception_p(opts, raise); } + if (argc > 0 && CLASS_OF(a1) == rb_cComplex && a2 == Qundef) { + return a1; + } return nucomp_convert(rb_cComplex, a1, a2, raise); } -- cgit v1.2.3