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 8166253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:47:48+00:00 2026-06-06T19:47:48+00:00

Need to make certain Ruby strings in my program to be immutable. What is

  • 0

Need to make certain Ruby strings in my program to be immutable. What is the best solution? Writing a wrapper over String class?

The freeze method won’t work for me. I see that freeze won’t allow you to unfreeze the object.

Following is my situation: I have a class that passes a string to a callback. This string happens to be an instance variable of the class and can be potentially large. I don’t want the callback to modify it, but still allow the class to modify it at will.

  • 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-06T19:47:49+00:00Added an answer on June 6, 2026 at 7:47 pm

    Following is my situation: I have a class that passes a string to a
    callback.

    Would passing a copy of the string to the callback work?

    This string happens to be an instance variable of the class
    and can be potentially large. I don’t want the callback to modify it,
    but still allow the class to modify it at will.

    If you’re worried about the size of the string, then using String#dup will help. It’ll create a new object, with a distinct object_id, but the contents of the string won’t be copied, unless the new string (or the original) gets modified. This is called “copy on write”, and is described in Seeing double: how Ruby shares string values.

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

Sidebar

Related Questions

I need to make a program that can read and edit certain .cdb files
I need to make a false referrer to certain pages using PHP. In my
I need to make a form that can display certain form inputs when another
I have situation where I need to make sure that user has completed certain
On a Linux, Apache, PHP site, I need to make certain that a subdirectory
I need to make a certain div contents to simulate a scroll, when new
I need to make certain requests in my web application use the https connector.Suppose
I need to make a Java component that turns the background a certain colour
I need to write a .htaccess rewrite command to make a certain URL behave
I'm writing a method to lift certain data out of an SQL query string,

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.