โ† Ruby Programming learning path
Ruby Programming ยท Module 5 of 10

Arrays and hashes

Arrays are ordered lists; hashes are key-value pairs.

๐Ÿ“– Key ideas

  1. Arrays: marks = [72, 85, 90]; marks[0] is 72; marks.last is 90.
  2. push or << adds items; pop removes the last one.
  3. Hashes: student = { name: "Asha", city: "Erode" }.
  4. Access with student[:name]; add with student[:age] = 20.
  5. Both have many built-in methods: size, include?, sort, keys, values.
๐Ÿ’ก Real-life example: An array is a numbered queue of students; a hash is the student's ID card with named fields.
ArrayOrdered list of values
HashKey-value pairs
<<Append an item to an array
keysAll keys of a hash