Project

General

Profile

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

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

View differences:

string.c
296 296
    }
297 297
}
298 298

  
299
/*
300
 *  call-seq:
301
 *     str.fstring -> str2
302
 *     str2.fstring -> str2
303
 *
304
 *  Returns a deduplicated and frozen string identical in content
305
 *  to <i>str</i>.  If <i>str</i> was already deduplicated and
306
 *  frozen (e.g. frozen string literal), then <i>str</i> itself
307
 *  is returned.
308
 */
299 309
RUBY_FUNC_EXPORTED
300 310
VALUE
301 311
rb_fstring(VALUE str)
......
10098 10108
    rb_define_method(rb_cString, "b", rb_str_b, 0);
10099 10109
    rb_define_method(rb_cString, "valid_encoding?", rb_str_valid_encoding_p, 0);
10100 10110
    rb_define_method(rb_cString, "ascii_only?", rb_str_is_ascii_only_p, 0);
10111
    rb_define_method(rb_cString, "fstring", rb_fstring, 0);
10101 10112

  
10102 10113
    rb_fs = Qnil;
10103 10114
    rb_define_hooked_variable("$;", &rb_fs, 0, rb_fs_setter);
test/ruby/test_string.rb
2549 2549
    assert_equal("\u3042", "\u3042\u3043".chr)
2550 2550
    assert_equal('', ''.chr)
2551 2551
  end
2552

  
2553
  def test_fstring
2554
    ts = 'fstring test case'.freeze
2555
    tmp = ts.dup
2556
    assert_same ts, tmp.fstring
2557
    assert_not_predicate tmp, :frozen?
2558
    assert_predicate tmp.fstring, :frozen?
2559
  end
2552 2560
end
2553 2561

  
2554 2562
class TestString2 < TestString
2555
-