Project

General

Profile

Feature #13077 ยป 0001-introduce-String-fstring-method.patch

normalperson (Eric Wong), 12/27/2016 01:50 AM

View differences:

string.c
}
}
/*
* call-seq:
* str.fstring -> str2
* str2.fstring -> str2
*
* Returns a deduplicated and frozen string identical in content
* to <i>str</i>. If <i>str</i> was already deduplicated and
* frozen (e.g. frozen string literal), then <i>str</i> itself
* is returned.
*/
RUBY_FUNC_EXPORTED
VALUE
rb_fstring(VALUE str)
......
rb_define_method(rb_cString, "b", rb_str_b, 0);
rb_define_method(rb_cString, "valid_encoding?", rb_str_valid_encoding_p, 0);
rb_define_method(rb_cString, "ascii_only?", rb_str_is_ascii_only_p, 0);
rb_define_method(rb_cString, "fstring", rb_fstring, 0);
rb_fs = Qnil;
rb_define_hooked_variable("$;", &rb_fs, 0, rb_fs_setter);
test/ruby/test_string.rb
assert_equal("\u3042", "\u3042\u3043".chr)
assert_equal('', ''.chr)
end
def test_fstring
ts = 'fstring test case'.freeze
tmp = ts.dup
assert_same ts, tmp.fstring
assert_not_predicate tmp, :frozen?
assert_predicate tmp.fstring, :frozen?
end
end
class TestString2 < TestString
-
    (1-1/1)