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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:24:25+00:00 2026-05-24T19:24:25+00:00

The actual problem I was originally doing was converting a hash of arrays into

  • 0

The actual problem I was originally doing was converting a hash of arrays into an array of hashes. If anyone has any comments on doing the conversion then that’s fine but the actual question I have is why the order of the hash keys change after editing them.

I’m fully aware of this question but this is not a duplicate. In fact I’m just having specific toruble in the order they are coming out in.

I have one array and one hash.

The array (@headers) contains a list of keys. @contents is a Hash filled with arrays. As explained, my task is to get an Array of hashes. So here’s my code, pretty straightforward.

@headers = (params[:headers])
puts "ORIGINAL PARAMS"
puts YAML::dump(@headers)


 @contentsArray = []  #The purpose of this is to contain hashes of each object

    @contents.each_with_index do |page,contentIndex|
      @currentPage = Hash.new

      @headers.each_with_index do |key, headerIndex|
        @currentPage[key] ="testing"
      end
      puts YAML::dump(@currentPage)
      @contentsArray[contentIndex] =@currentPage
    end
    puts "UPDATED CONTENTS"
    puts YAML::dump(@contentsArray[0])

Heres the bit I cant wrap my head around. The keys of the original params are in a different order than the updated one.

Note the :puts “ORIGINAL PARAMS” & puts “UPDATED CONTENTS” parts. This is their output:

ORIGINAL PARAMS
--- 
- " Page Title      "
- " WWW "
- " Description     "
- " Keywords        "
- " Internal Links  "
- " External Links  "
- " Content files   "
- " Notes           "
--- 


UPDATED CONTENTS
--- 
" WWW ": page
" Internal Links  ": testing
" External Links  ": testing
" Description     ": testing
" Notes           ": testing
" Content files   ": testing
" Page Title      ": testing
" Keywords        ": testing

Why is this?

for the record. Printing @currentPage after the header loop gives this:

" WWW ": page
" Internal Links  ": page
" External Links  ": page
" Description     ": page
" Notes           ": page
" Content files   ": page
" Page Title      ": page
" Keywords        ": page

So it must be the way the values and keys are assigned to the @currentPage and not when It goes into the array.

  • 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-24T19:24:27+00:00Added an answer on May 24, 2026 at 7:24 pm

    In Ruby 1.8+ Hashes are UNSORTED lists

    The order in which you traverse a hash by either key or value may seem arbitrary, and will generally not be in the insertion order.

    While in RUBY 1.9+ they are sorted in order you push items.

    Hashes enumerate their values in the order that the corresponding keys were inserted.

    http://apidock.com/ruby/v1_9_2_180/Hash

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

Sidebar

Related Questions

I have the following code: The actual problem is the non-quoted code. I want
I am very new to sql.The actual problem is much bigger. I need information
This is more of a theoretical question than an actual problem I have. If
The video player actually loads fine. My actual problem is when I refresh some
I asked a separate question (now deleted) for what I thought the actual problem
Am facing a problem, while creating components through TOM API using .NET/COM Interop. Actual
I've created an example of the problem here: http://jsfiddle.net/JustinN/qWeLT/1/ My actual code is hooked
I am starting to learn Java. The actual language is not a problem since
I have just started putting JSLint into my build pipeline and it has been
Ok, my actual problem was this: I was implementing an IList<T> . When 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.