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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:01:57+00:00 2026-06-02T21:01:57+00:00

hash = Hash.new(Hash.new([])) hash[1][2] << 3 hash[1][2] # => [3] hash # => {}

  • 0
hash = Hash.new(Hash.new([]))
hash[1][2] << 3

hash[1][2] # => [3]
hash # => {}
hash.keys # => []
hash.values # => []

What’s going on? Ruby’s hiding data (1.9.3p125)

  • 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-02T21:01:59+00:00Added an answer on June 2, 2026 at 9:01 pm

    What’s going on? Ruby’s hiding data (1.9.3p125)

    Ruby hides neither data nor its docs.

    Default value you pass into the Hash constructor is returned whenever the key is not found in the hash. But this default value is never actually stored into the hash on its own.

    To get what you want you should use Hash constructor with block and store default value into the hash yourself (on both levels of your nested hash):

    hash = Hash.new { |hash, key| hash[key] = Hash.new { |h, k| h[k] = [] } } 
    
    hash[1][2] << 3
    
    p hash[1][2]  #=> [3]
    p hash        #=> {1=>{2=>[3]}}
    p hash.keys   #=> [1]
    p hash.values #=> [{2=>[3]}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm kinda new to Flex. I have trying to send Hash from Ruby on
Ruby 1.9 has a few new syntax elements, such as the {key: value} hash
I have a hash in which I want to use the values as keys
The documentation for g_hash_table_new() indicates Hash values are used to determine where keys are
If my math is right, I can quickly generate a new hash value for
Is there a way to return a new version of an array/hash that does
I have a hash table where the keys are rather complex lists, with sublists
I have array of words and I want to get a hash, where keys
You would think that if two dictionaries contained the same keys and values they
I have a script that utilizes a hash, which contains four strings as keys

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.