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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:21:15+00:00 2026-06-11T15:21:15+00:00

Possible Duplicate: Is Ruby pass by reference or by value? Working with Ruby, when

  • 0

Possible Duplicate:
Is Ruby pass by reference or by value?

Working with Ruby, when passing an object to a method, how is the memory of this object handled?

Coming from a C background, I can think of several things which may be happening:

  1. A copy of the memory associated with the according object and is made available to the method being called. In which case the modification of the object would only be reflected in the context of method being called, and not the calling method.

  2. A reference to the memory of the object is passed the method being called (essentially a pointer). Hence any changes made by the object by the method being called or the calling method would be reflected in both contexts. As well, should this program be multithreaded, some kind of mechanism (mutex, semaphore, etc.) must be used to ensure mutually exclusive access to that memory performing write operations.

  3. Something else I am unable to think of… maybe a memory model similar to that of Go… Pipes… MessagePassing…?

What is actually happening?

  • 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-11T15:21:16+00:00Added an answer on June 11, 2026 at 3:21 pm

    Ruby uses pass-by-value, or more precisely, a special case of pass-by-value where the value being passed is always a pointer. This special case is also sometimes known as call-by-sharing, call-by-object-sharing or call-by-object.

    It’s the same convention that is used by more or less every object-oriented language ever created.

    Note: on all existing Ruby implementations Symbols, Fixnums and Floats are actually passed directly by value and not with an intermediary pointer. However, since those three are immutable, there is no observable behavioral difference between pass-by-value and call-by-object-sharing in this case, so you can greatly simplify your mental model by simply treating everything as call-by-object-sharing. Just interpret these three special cases as internal compiler optimizations that you don’t need to worry about.

    Here’s a simple example you can run to determine the argument passing convention of Ruby (or any other language, after you translate it):

    def is_ruby_pass_by_value?(foo)
      foo.replace('More precisely, it is call-by-object-sharing!')
      foo = 'No, Ruby is pass-by-reference.'
      return nil
    end
    
    bar = 'Yes, of course, Ruby *is* pass-by-value!'
    
    is_ruby_pass_by_value?(bar)
    
    p bar
    # 'More precisely, it is call-by-object-sharing!'
    

    In short: it’s your option 2.

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

Sidebar

Related Questions

Possible Duplicate: 'pass parameter by reference' in Ruby? in this example: def test verb
Possible Duplicate: check if value exists in array in Ruby I have this method
Possible Duplicate: Why do this Ruby object have two to_s and inspect methods that
Possible Duplicate: Ruby code to extract host from URL string I found this module
Possible Duplicate: Python or Ruby Interpreter on iOS I just discovered this apps pypad
Possible Duplicate: Running a command from Ruby displaying and capturing the output I have
Possible Duplicate: Array slicing in Ruby: looking for explanation for illogical behaviour (taken from
Possible Duplicate: Ruby.Metaprogramming. class_eval I have this little project, the goal is to create
Possible Duplicate: Ruby Assignment Syntax I don't get the concept of an assignment method
Possible Duplicate: Array slicing in Ruby: looking for explanation for illogical behaviour (taken from

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.