Ruby - Arrays
How can you create an array of 5 hashes, each with keys :a and :b initialized to 0, ensuring each hash is a separate object?
Array.new(5, {a: 0, b: 0}) or [{a: 0, b: 0}] * 5 repeats the same hash object 5 times.Array.new(5) { {a: 0, b: 0} } runs the block 5 times, creating 5 separate hashes.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions