Rudimentary irb testing suggests that Ruby Hash returns .keys and .values in matching order. Is it safe to assume that this is the case?
Rudimentary irb testing suggests that Ruby Hash returns .keys and .values in matching order.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Yes. According to the Ruby Docs for Hash, “Hashes enumerate their values in the order that the corresponding keys were inserted.” So you should always get the same order for a hash if it is created in the same way.