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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:10:28+00:00 2026-05-13T19:10:28+00:00

Despite reading Understanding Ruby Symbols , I’m still confused by the representation of the

  • 0

Despite reading “Understanding Ruby Symbols“, I’m still confused by the representation of the data in memory when it comes to using symbols. If a symbol, two of them contained in different objects, exist in the same memory location, then how is it that they contain different values? I’d have expected the same memory location to contain the same value.

This a quote from the link:

Unlike strings, symbols of the same name are initialized and exist in memory only once during a session of ruby

I don’t understand how it manages to differentiate the values contained in the same memory location.

Consider this example:

patient1 = { :ruby => "red" }
patient2 = { :ruby => "programming" }

patient1.each_key {|key| puts key.object_id.to_s}
3918094
patient2.each_key {|key| puts key.object_id.to_s}
3918094

patient1 and patient2 are both hashes, that’s fine. :ruby however is a symbol. If we were to output the following:

patient1.each_key {|key| puts key.to_s}

Then what will be output? "red", or "programming"?

Forgetting hashes for a second, I’m thinking a symbol is a pointer to a value. The questions I have are:

  • Can I assign a value to a symbol?
  • Is a symbol just a pointer to a variable with a value in it?
  • If symbols are global, does that mean a symbol always points to one thing?
  • 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-13T19:10:28+00:00Added an answer on May 13, 2026 at 7:10 pm

    Consider this:

    x = :sym
    y = :sym
    (x.__id__ == y.__id__ ) && ( :sym.__id__ == x.__id__) # => true
    
    x = "string"
    y = "string"
    (x.__id__ == y.__id__ ) || ( "string".__id__ == x.__id__) # => false
    

    So, however you create a symbol object, as long as its contents are the same, it will refer to the same object in memory. This is not a problem because a symbol is an immutable object. Strings are mutable.


    (In response to the comment below)

    In the original article, the value is not being stored in a symbol, it is being stored in a hash. Consider this:

    hash1 = { "string" => "value"}
    hash2 = { "string" => "value"}
    

    This creates six objects in the memory — four string objects and two hash objects.

    hash1 = { :symbol => "value"}
    hash2 = { :symbol => "value"}
    

    This only creates five objects in memory — one symbol, two strings and two hash objects.

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

Sidebar

Related Questions

Despite reading lots of other posts regarding GIT and moved files I still struggle
Despite reading many articles (some on this board) I am still scratching my head
I'm certain that I'm missing some fundamental understanding of iOS memory management and, despite
Despite me reading wikipedia and such, I still don't really understand what Thread Safety
Despite using PHP for years, I've never really learnt how to use expressions to
I encountered an error. Despite declaring the variables (failturetext and userName) errors still appear.
I have a piece of code here that does not work despite me using
I have been reading for the last two days about indexes and how to
I am using the Android ADT Bundle for dev work. After reading multiple guides
HI Gurus, I'm looking to replace an IN clause with exists, but despite reading

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.