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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:34:55+00:00 2026-05-14T19:34:55+00:00

I am passing the reference of name to mod_name , I modify the referenced

  • 0

I am passing the reference of name to mod_name, I modify the referenced object from within the method but the change is not visible outside of the method, if I am referring to the same object from all locations how come the value is different depending on where I reference it?

name = "Jason"

puts name.object_id      #19827274

def mod_name(name)
  puts name.object_id    #19827274
  name = "JasonB"
end

puts name.object_id      #19827274

puts name                #Jason

String might be a bad example, but I get the same result even if I use a Fixnum.

  • 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-05-14T19:34:55+00:00Added an answer on May 14, 2026 at 7:34 pm

    As Greg mentions, in your example you’re creating a new local variable called name that is shadowing your parameter. This is due to behavior called copy-on-write. If you wanted the function to affect the object the parameter references, you could use replace instead of doing an assignment, like this:

    def mod_name(name)
      name.replace('JasonB')
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am passing a JSON object as a reference to my custom jquery widget
I am passing an object from the controller to the view. The object contains
I have a method where I am passing in two object, which have the
What is the difference between passing-by-reference and using the C pointer notation? void some_function(some_type&
I'm having a bit of difficulty passing a reference type between webservices. My set
I got the answer NO! Because passing by value and passing by reference looks
I have a problem with passing variables as reference in PHP. I want to
Is there a performance benefit by passing ints by reference rather than by value
I know that when it comes to passing objects in java, the reference of
passing post data using cURL requires that the name of the input. However, I

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.