Setting Default Character Encodings ruby 1.9

Discussion in 'Ruby' started by Andrew Barringer, Aug 13, 2009.

  1. This is probably something stupid simple I'm overlooking.. but.. here it
    goes.

    =20

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

    =20

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

    =20

    my scratch.rb file has the following line:

    =20

    p __ENCODING__

    =20

    The output is always this:

    =20

    #<Encoding:US-ASCII>

    =20

    I want it to be this:

    =20

    #<Encoding:US-ASCII-8BIT>

    =20

    What am I doing wrong?

    =20

    Thanks,

    Andy
     
    Andrew Barringer, Aug 13, 2009
    #1
    1. Advertising

  2. On Thu, Aug 13, 2009 at 10:39 AM, Andrew
    Barringer<> wrote:
    > 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>


    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

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

    -greg
     
    Gregory Brown, Aug 13, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Safalra
    Replies:
    8
    Views:
    645
    Roedy Green
    Jun 15, 2004
  2. Kenneth McDonald
    Replies:
    1
    Views:
    323
  3. JKPeck
    Replies:
    6
    Views:
    307
    Martin Miller
    Nov 14, 2006
  4. Replies:
    7
    Views:
    3,634
  5. Stefan Schmidt

    character-encodings gem with Ruby 1.9

    Stefan Schmidt, Jul 10, 2008, in forum: Ruby
    Replies:
    3
    Views:
    194
    Ollivier Robert
    Jul 15, 2008
Loading...

Share This Page