Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to keep the order in ruby hashes

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 284
    Comment on it

    When we insert the data into a ruby hash it reorders the data in some other order when we use it in view file.So there are cases when we have to show the data in the same order in the order we are inserting the data into ruby hash.So in case where we have to maintain the order we should use OrderedHash in replacement of Hash.The syntax is as follows:

    **hash_name = ActiveSupport::OrderedHash.new**

    where hash_name is the name of the hash

    For example: If we insert Jan,Feb,Mar,April etc in this case it will basically maintains the order of the hash.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: