What's the difference between arrays and hashes in Ruby?
Ruby-on-rails – What’s the difference between arrays and hashes
arrayshashrubyruby-on-rails
Related Question
- Javascript – What’s the difference between “Array()” and “[]” while declaring a JavaScript array
- Javascript – How to get the difference between two arrays in JavaScript
- Javascript – How to merge two arrays in JavaScript and de-duplicate items
- Fundamental difference between Hashing and Encryption algorithms
- Javascript – How to remove a specific item from an array
- Ruby – What’s the difference between equal?, eql?, ===, and ==
- Javascript – Copy array by value
- Ruby-on-rails – Difference between rake db:migrate db:reset and db:schema:load
Best Solution
From Ruby-Doc:
Arrays are ordered, integer-indexed collections of any object. Array indexing starts at 0, as in C or Java. A negative index is assumed to be relative to the end of the array—that is, an index of -1 indicates the last element of the array, -2 is the next to last element in the array, and so on. Look here for more.
A Hash is a collection of key-value pairs. It is similar to an Array, except that indexing is done via arbitrary keys of any object type, not an integer index. Hashes enumerate their values in the order that the corresponding keys were inserted.
Hashes have a default value that is returned when accessing keys that do not exist in the hash. By default, that value is nil. Look here for more.