4 ms·
It's documented that the default encoding in ruby is UTF-8. > "\xAA".force_encoding('binary').split('') # => ["\xAA"] If you want a binary string, you
by spoiler 9y ago
It's documented that the default encoding in ruby is UTF-8.
> "\xAA".force_encoding('binary').split('')
# => ["\xAA"]
If you want a binary string, you can do
str = String.new('...', encoding: 'binary')
NOTE: `'binary'` is an alias for `Encoding::ASCII_8BIT`
- masklinn 9y ago> It's documented that the default encoding in ruby is UTF-8. The complaint is not that the default string has no encoding, it's that proper encoding is not validated when creating the string, but only when processing it (and even then it might depend on the actual operation being applied). So given (1) a string object with (2) a proper encoding, it may still blow up in your face at any point unless you defensively check every string you get with `valid_encoding?`