# Setting Default Character Encodings ruby 1.9

**URL:** <https://www.ruby-forum.com/t/setting-default-character-encodings-ruby-1-9/173706>\
**Category:** Ruby\
**Created:** [August 13, 2009, 4:39pm UTC](https://www.ruby-forum.com/t/setting-default-character-encodings-ruby-1-9/173706 "2009-08-13T16:39:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfsog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bfsog](https://www.ruby-forum.com/u/bfsog)\
**Post date:** [August 13, 2009, 4:39pm UTC](https://www.ruby-forum.com/t/setting-default-character-encodings-ruby-1-9/173706/1 "2009-08-13T16:39:46Z")

</div>

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

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:

p **ENCODING**

The output is always this:

#Encoding:US-ASCII

I want it to be this:

#Encoding:US-ASCII-8BIT

What am I doing wrong?

Thanks,

Andy

---

<div class="post-metadata">

**Author:** ![bfsog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bfsog](https://www.ruby-forum.com/u/bfsog)\
**Post date:** [August 13, 2009, 4:49pm UTC](https://www.ruby-forum.com/t/setting-default-character-encodings-ruby-1-9/173706/2 "2009-08-13T16:49:44Z")

</div>

On Thu, Aug 13, 2009 at 10:39 AM, Andrew  
Barringer[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ruby19 -E ASCII-8BIT:ASCII-8BIT scratch.rb
> 
> The output is always this:
> 
> #Encoding:US-ASCII

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  
comment.  
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  
series:  
[http://blog.grayproductions.net/categories/character\_encodings](http://blog.grayproductions.net/categories/character_encodings)

You can also read the m17n chapter of my book:  
[http://rubybestpractices.com](http://rubybestpractices.com)

-greg
