i have an array with 3 elements, each is a hash. how to print the third hash? in ruby

To have an array with 3 elements, each being a hash, you can create an array and assign hashes to its elements. Here's an example:

main.rb
array = [
  {key1: "value1"},
  {key2: "value2"},
  {key3: "value3"}
]
71 chars
6 lines

To print the third hash, you can use the index 2 (arrays are zero-based). Here's how you can do it:

main.rb
puts array[2]
14 chars
2 lines

This will output the third hash {key3: "value3"}.

related categories

gistlibby LogSnag