Created
January 11, 2012 23:34
-
-
Save erik-megarad/1597477 to your computer and use it in GitHub Desktop.
For fun, run this at home
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ["US-ASCII", "ASCII-8BIT", "UTF-8"].each do |encoding| | |
| Encoding.default_internal = encoding | |
| puts "With #{encoding} default internal:" | |
| [127, 255, 256].each do |number| | |
| no_arg = number.chr.encoding rescue "out of range" | |
| puts "#{number}.chr is: #{no_arg}" | |
| with_arg = number.chr(encoding).encoding rescue "out of range" | |
| puts "#{number}.chr('#{encoding}') is: #{with_arg}" | |
| end | |
| puts "" | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Spoiler: here's the output: