0

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: '')
harinsamaranayake
  • 751
  • 2
  • 12
  • 32

1 Answers1

1

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.

Stefan
  • 109,145
  • 14
  • 143
  • 218