Setting Default Character Encodings ruby 1.9

This is probably something stupid simple I’m overlooking… but… here it

I’m trying to set the default character encoding at the command line
like this:

ruby19 -E ASCII-8BIT:ASCII-8BIT scratch.rb

my scratch.rb file has the following line:


The output is always this:


I want it to be this:


What am I doing wrong?



On Thu, Aug 13, 2009 at 10:39 AM, Andrew
Barringer[email protected] wrote:

ruby19 -E ASCII-8BIT:ASCII-8BIT scratch.rb

The output is always this:


Hi, this is because -E sets the internal/external encodings. If you
want to set the source encoding, you need to do this with a magic
If you want ASCII-8BIT, the first line of your source file would look
like this:

encoding: ASCII-8BIT.

For more on encodings in Ruby 1.9, you should definitely JEG2’s blog

You can also read the m17n chapter of my book:


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs