The arr
and freq
objects are local to the peak_hours
method, so they are destroyed whenever the method ends. It looks like you are calling the peak_hours
method for every reg_date, and each time you call it it's making a new array and a new frequency hash, putting just the one value in each of them.
I think what you want to do is make your frequency hash right before wherever you are looping through your reg_dates, then update the frequency hash for each reg_date right inside the loop.