From b2da3824c5cc03658c652ed810ee0e322bd62b80 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 18 Sep 2017 02:27:13 +0000 Subject: refinements in string interpolation * compile.c (iseq_compile_each0): insert to_s method call, so that refinements activated at the caller should take place. [Feature #13812] * insns.def (tostring): fix up converted object to a string, infect and fallback. * insns.def (branchiftype): new instruction for conversion. branches if TOS is an instance of the given type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'string.c') diff --git a/string.c b/string.c index c32b363324..bbd23669e6 100644 --- a/string.c +++ b/string.c @@ -1404,6 +1404,8 @@ str_shared_replace(VALUE str, VALUE str2) } } +VALUE rb_obj_as_string_result(VALUE str, VALUE obj); + VALUE rb_obj_as_string(VALUE obj) { @@ -1413,6 +1415,12 @@ rb_obj_as_string(VALUE obj) return obj; } str = rb_funcall(obj, idTo_s, 0); + return rb_obj_as_string_result(str, obj); +} + +VALUE +rb_obj_as_string_result(VALUE str, VALUE obj) +{ if (!RB_TYPE_P(str, T_STRING)) return rb_any_to_s(obj); if (!FL_TEST_RAW(str, RSTRING_FSTR) && FL_ABLE(obj)) -- cgit v1.2.3