Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
String#ascii_only?
() -> bool
ascii_only? → true or false
string.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/string.rb, line 21
def ascii_only?
Primitive.attr! :leaf
Primitive.cexpr! 'rb_str_is_ascii_only_p(self)'
end
Returns whether self contains only ASCII characters:
Example
'abc'.ascii_only? # => true "abc\u{6666}".ascii_only? # => false
Related: see Querying.