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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:20:57+00:00 2026-05-24T14:20:57+00:00

I am looking for a way to maintain the insert order for a Hash

  • 0

I am looking for a way to maintain the insert order for a Hash that I am using in Ruby. My data is coming from a database and is already grouped/ordered the way I want it, but Ruby doesn’t guarantee maintained order in Hashs in my version 1.8.4.

Is there any workaround for this? If not is there a way I could create a custom comparator?

Here is the Hash:

{
"February"=>[0.5667, 14.6834, 79.7666, 261.8668, 342.1167, 723.517], 
"March"=>[0.0, 26.4667, 554.45, 681.3164, 2376.0668, 10353.0358], 
"May"=>[2.75, 34.6666, 342.1831, 1331.8999, 1589.617, 9282.9662], 
"July"=>[1.9, 2.3666, 59.45, 302.1501, 554.1652, 5195.0839], 
"June"=>[0.15, 24.2166, 244.1498, 335.6834, 536.067, 1498.949], 
"August"=>[0.0, 0.4, 9.3668, 30.7164, 67.7504, 162.0337], 
"April"=>[0.0, 8.3, 68.9331, 357.9168, 815.9662, 2870.217]
 }

Any ideas would be great,
Thanks

  • 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-24T14:20:58+00:00Added an answer on May 24, 2026 at 2:20 pm

    You can keep a list on the side containing the keys in sorted order

    initially:

    hash = {}
    keys = []
    

    on insert:

    def insert(key, value)
      keys << key unless hash[key]
      hash[key] = value
    end
    

    to iterate in insertion order:

    for key in keys do
      puts key, hash[key]
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a good way to maintain permissions on who can add data
I'm looking for a way to non-destructively alter data. I have one table that
I am looking for a way to maintain PHP sessions across multiple domains on
I'm looking for way to PHP to detect if a script was run from
I am using codeigniter and looking a way to enable directly editting of doc
I am using the jquery-ui-dialog plugin I am looking for way to refresh the
I looking for a way, specifically in PHP that I will be guaranteed to
What is the best way to maintain a unique ID field across multiple database
I'm looking for a way to add properties to my already defined class at
Hey, I'm looking for the most efficient way to maintain an object relative auto-incrementing

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.