Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Returns true if str starts with one of the prefixes given. Each of the prefixes should be a String or a Regexp.
"hello".start_with?("hell")               #=> true
"hello".start_with?(/H/i)                 #=> true

# returns true if one of the prefixes matches.
"hello".start_with?("heaven", "hell")     #=> true
"hello".start_with?("heaven", "paradise") #=> false
               static VALUE
rb_str_start_with(int argc, VALUE *argv, VALUE str)
    int i;

    for (i=0; i<argc; i++) {
        VALUE tmp = argv[i];
        if (RB_TYPE_P(tmp, T_REGEXP)) {
            if (rb_reg_start_with_p(tmp, str))
                return Qtrue;
        else {
            rb_enc_check(str, tmp);
            if (RSTRING_LEN(str) < RSTRING_LEN(tmp)) continue;
            if (memcmp(RSTRING_PTR(str), RSTRING_PTR(tmp), RSTRING_LEN(tmp)) == 0)
                return Qtrue;
    return Qfalse;

Was this page useful?