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

  • SEARCH
  • Home
  • 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 107183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:42:50+00:00 2026-05-11T01:42:50+00:00

This may be a bit of a nooby question, I have been trying to

  • 0

This may be a bit of a nooby question, I have been trying to get better at ruby recently, and started reading the fantastic The Ruby Programming Language. Something that was mentioned is that string literals are considered mutable, so in a loop it is better to use a variable then a literal, as a new string will get instantiated at every iteration.

My question is why? At first I thought it was because of interpolation, but symbols are immutable and they support interpolation. Coming from a static background, it doesn’t really make much sense to me.

EDIT:

After reading thenduks answer, I think I may have it. AFAIK, languages like Java or C# don’t have destructive string methods (they use upcase, but not upcase!). Because of things like upcase! or <<, the literal cannot be immutable.

Not 100% sure on that, the other possibility is that it is a compile-time interning that happens, which is something that just doesn’t happen in a scripting language.

  • 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. 2026-05-11T01:42:51+00:00Added an answer on May 11, 2026 at 1:42 am

    Not really sure what exactly your question is, but consider the following code:

    10.times { puts 'abc'.object_id } 

    This prints out 10 different id’s. Why? Just because you know this string wont change doesn’t mean Ruby does. If you think that 'abc' should only be created once then what happens if you do:

    10.times { puts 'abc'.upcase! } 

    The upcase! method mutates the string to be upper case, on the next iteration the string created in the first iteration isn’t the same anymore.

    Perhaps post a code example that is confusing to you?

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

Sidebar

Related Questions

This may be a bit silly question, but I just started doing pretty things
Ok this may seem like a bit of a noob question but one many
This may sound a bit provocative but it actually is a real question. Feel
This may be a bit of an easy, headdesk sort of question, but my
This may be a bit of daft question, but I don't come from an
This may be a bit of a weird question, but is there any reliable
This one may be a bit strange. I have a solution in Visual Studio
This may be a silly question but should I use the 32 bit or
This may be a matter of style, but there's a bit of a divide
This may seem like a daft question, but i was wondering about how to

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.