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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:44:33+00:00 2026-06-05T08:44:33+00:00

In Ruby 1.9 a Hash is sorted on the basis of order of insertion.

  • 0

In Ruby 1.9 a Hash is sorted on the basis of order of insertion.
Why the Ruby koans’s assertion on test_hash_is_unordered method returns true?

To me, the method’s title is quite misleading… maybe it refers to the fact that Ruby will recognize 2 equal hashes that were created with different keys order insetions.

But, theorically, this kind of assertion:

hash1 = { :one => "uno", :two => "dos" }
hash2 = { :two => "dos", :one => "uno" }

assert_equal ___, hash1 == hash2

Should return false. Or not?

  • 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-05T08:44:34+00:00Added an answer on June 5, 2026 at 8:44 am

    From the fine manual:

    hsh == other_hash → true or false

    Equality—Two hashes are equal if they each contain the same number of keys and if each key-value pair is equal to (according to Object#==) the corresponding elements in the other hash.

    So two Hashes are considered equal if they have the same key/value pairs regardless of order.

    The examples in the documentation even contain this:

    h2 = { 7 => 35, "c" => 2, "a" => 1 }
    h3 = { "a" => 1, "c" => 2, 7 => 35 }
    h2 == h3   #=> true
    

    Yes, the test_hash_is_unordered title is somewhat misleading as order isn’t specifically being testing, only order with respect to equality is being demonstrated.

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

Sidebar

Related Questions

The hash method on a Ruby String returns a number based on the string's
Rudimentary irb testing suggests that Ruby Hash returns .keys and .values in matching order.
I have a Ruby hash: @tags = { project_status => { title => Project
In order to implement auto-vivification of Ruby hash, one can employ the following class
I need to hold values in sorted hash in ruby (1.8.7). What data structed
I am new to Ruby. I have a (already sorted) hash with the following
I've got a ruby hash like this [{user_id: 3, purchase: {amount: 2, type_id:3, name:chocolate},
Provided the following ruby hash: { cat: { 1: 2, 2: 10, 3: 11,
I have a ruby hash that I'd like to render using RABL . The
How to convert Ruby Hash to C# Dictionary? Do we have any built-in function...or

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.