Related to this this. What is meant by binary
here? Knows it is related to source format but not sure whether it is ASCII-8BIT.
string.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
CodePudding user response:
With two positional arguments, they specify destination and source encoding respectively.
'binary'
is an alias for 'ASCII-8BIT'
:
Encoding::BINARY.names
#=> ["ASCII-8BIT", "BINARY"]
Note that you can omit the second argument ('binary'
) if your string is already in binary encoding.