There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
what is the purpose of using Hash.new?
I understand using hashes that asign values to keys. But what is Hash.new achieving if it isn’t assigning value to anything?
Is there a benefit to using obj = Hash.new rather than obj = {} when they do the same thing? It seems obj = {} would be more efficient considering the difference in the number of characters.
The number of characters is not a sign of efficiency; to determine that we examine time complexity, especially of loops, and space complexity in terms of how much memory is consumed.
Declaring a literal hash is okay when the values are random data. The advantage we gain with Hash.new is an initial default value for each additional member.
Eg.
hist = Hash.new(0)
This will come up in the Build a Histogram exercise.