Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:02:41+00:00 2026-06-02T18:02:41+00:00

I’m reading The Ruby Programming Language. In section 3.2.6.1, Multibyte characters in Ruby 1.9,

  • 0

I’m reading “The Ruby Programming Language”. In section 3.2.6.1, “Multibyte characters in Ruby 1.9”, the book introduces an optimization in Ruby’s string

If a string literal contains only 7-bit ASCII characters, then its encoding method will return ASCII, even if the source encoding is UTF-8

I tried the following simple script on both ruby 1.9.1-p431, 1.9.2 and 1.9.3-p125, both uses UTF-8 encoding for 7-bit ASCII characters.

# coding: utf-8
s = 'hello'
p s.encoding
# result is #<Encoding:UTF-8>

I guess maybe this behavior is changed during the development of Ruby 1.9. I tried to search Ruby 1.9’s changelog, and the 1.9.1 changelog confirms this behavior. I also cloned Ruby’s git repository but I can’t find the commit mentioning about changing this behavior.

Update:

Looking at Ruby’s source code repository, I guess this is the behavior in Ruby 1.9.0, which was released in Jan, 2008. (It failed to compile on Debian 6 so I can’t exactly confirm this.) Though “The Ruby Programming Language” is an excellent book, it’s originally published in 2008. It’s very likely that some descriptions in the book are outdated.

Another outdated description is about the Encoding.list method behavior. So be careful of outdated description if you are also reading this book.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:02:42+00:00Added an answer on June 2, 2026 at 6:02 pm

    I don’t have that book, but The current Pdf version of the Programming Ruby book (the pickaxe) states

    String literals are always encoded using the encoding of the source file that contains them, regardless of the content of the string

    And then gives an example where "dog" gains the utf-8 encoding. Looks like the edition of the book you have is wrong. Whether that was an errata in the print version of your book or just the fact that ruby changed after it was printed, I don’t know

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.