How to write "string" .encode ("us-ascii") in ruby 1.8.7?
1 answer
The string.encode ("us-ascii") method converts all characters in the string to 7-bit ASCII United States values.
US-ASCII is essentially plain text with a total of 128 characters. This encoding was common on United States computers in the 1970s and 1990s.
The reason you are now seeing this is probably because you are using email. The email protocol requires US-ASCII encoding for strings.
Ruby 1.8.7 has no built-in string encoding methods, as Ruby 1.8.7 stores strings as bytes, not encoded characters.
For converting to Ruby 1.8.7 see Iconv library:
http://ruby-doc.org/stdlib-1.8.7/libdoc/iconv/rdoc/Iconv.html
Also see the sample iconv conversion code in this answer:
+3
source to share