Method: String#ascii_only?

Defined in:
string.c

#ascii_only?Boolean

Returns true if self contains only ASCII characters, false otherwise:

'abc'.ascii_only?         # => true
"abc\u{6666}".ascii_only? # => false

Returns:

  • (Boolean)


11444
11445
11446
11447
11448
11449
11450
# File 'string.c', line 11444

static VALUE
rb_str_is_ascii_only_p(VALUE str)
{
    int cr = rb_enc_str_coderange(str);

    return RBOOL(cr == ENC_CODERANGE_7BIT);
}