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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:28:43+00:00 2026-06-07T04:28:43+00:00

I run into a lot of situations where I’m modifying a variable with a

  • 0

I run into a lot of situations where I’m modifying a variable with a method and setting it to that modified value e.g…

value = "string"
value.modify #=> "new string"
value #=> "string"
value = value.modify
value #=> "new string"

I noticed that many Ruby methods have a value.modify! varient that does just that.

Is there a shorthand in Ruby for doing value = value.modify?
Also if I was ever to make my own modify! method how would I go about implementing it?

  • 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-07T04:28:46+00:00Added an answer on June 7, 2026 at 4:28 am

    It really depends on how the class is implemented. These bang-methods are not really possible on immutable objects like Symbols or Fixnums. For Enumerables like Arrays, there is a replace() method that lets you write any bang-method like this:

    def bang()
      replace(this.non_bang)
    end
    

    If you look at the source of many bang-methods, you will see that normally the bang-methods contain the meat of the code and the non-bang methods simply call dup() or clone() on the object and then call the bang version of the method like this:

    def non_bang(*args)
      clone.bang(*args)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've run into a lot of posts in various forums showing a new format
I seem to run into this situation quite a lot and have yet to
I have run into a strange problem, i am creating a lot of dynamically
I have made some helper functions that run a simulation using a lot of
I've run into a javascript question that I don't know how to resolve. I'm
I've run into the same problem a lot of people seem to face coming
I run into this problem. I have a textarea which I only want to
I run into follow problem. Did I miss anything? Association.all().count() 1 Association.all().fetch(1) [Association(**{'server_url': u'server-url',
I run into the following issue semi-regularly: I make changes to XAML or some
I run into the following errors when i try to store a large file

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.