1
2.1.1 :025 > grouped_values = Hash.new([])
 => {}
2.1.1 :026 > grouped_values["positive"].push(3)
 => [3]
2.1.1 :027 > grouped_values
 => {} # <= This is bugging me 
2.1.1 :028 > grouped_values["positive"]
 => [3]

I was solving one of the problems presented on hackerrank and came about this interesting behaviour of the Hash class. My question here is why does it happen? Why does it say it's empty even though the [] operator returns proper values? Anyone can point me towards a proper explanation?

Mike
  • 11
  • 1

0 Answers0