How to write "string" .encode ("us-ascii") in ruby ​​1.8.7?

I'm trying to use gmail_xoauth, and unfortunately this gem uses encode("us-ascii")

for strings, which is only available for Ruby 1.9.3.

I'm not familiar with encode

Ruby 1.9.3, so I'm wondering what is "string".encode("us-ascii")

and how to write it in 1.8.7?

+3


source to share


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:

String.force_encoding () in Ruby 1.8.7 (or Rails 2.x)

+3


source







All Articles