A summary table of text below: How can I display accented characters (so that they work through puts, etc.) in Ruby?
Hello! I am writing a program for my class that will display some sentences in Spanish. When I try to use accented characters in Ruby, they do not display correctly (in the NetBeans output window (which displays characters with an accent in Java in order) or on the command line).
At first, some of my code didn’t even run, because the accented characters in my arrays were throwing the Ruby breaker (I suppose?). I got errors like Ruby was expecting parentheses to close.
But I did some research and found a solution to add the following line of code to the beginning of my Ruby file:
# coding: utf-8
In NetBeans, my program ran independently of this line. But I needed to add this line so that my program runs successfully on the command line. (I do not know why.)
I still have a problem displaying characters on the screen. The word "será" will appear in the NetBeans output window as "seré". And on the command line, he draws small channel characters (which I don’t know how to type).
After doing some more research, I heard about:
$KCODE = 'UTF-8'
but i'm out of luck with that.
I use Ruby 1.8 and 1.9 (I go back and forth between different machines).
Thanks Derek
Derek source share