# Frozen hash problem

**URL:** <https://www.ruby-forum.com/t/frozen-hash-problem/185615>\
**Category:** Rails\
**Created:** [March 23, 2010, 4:34pm UTC](https://www.ruby-forum.com/t/frozen-hash-problem/185615 "2010-03-23T16:34:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [March 23, 2010, 4:34pm UTC](https://www.ruby-forum.com/t/frozen-hash-problem/185615/1 "2010-03-23T16:34:36Z")

</div>

I’d like to delete some records before saving them. I ran this  
experiment:

before\_save :prune\_lab\_datas

def prune\_lab\_datas  
lab\_datas.each do |lab\_data|  
lab\_data.destroy  
end  
raise lab\_datas.to\_yaml  
end

But nothing seems to be deleted in the hash:

* * *

- &id001 !ruby/object:LabData  
attributes:  
created\_at: 2010-03-21 22:16:06  
unit\_id: “3”  
lab\_id: “81”  
updated\_at: 2010-03-21 22:16:06  
id: “184”  
lab\_desc\_id: “6”  
value: “29”  
attributes\_cache: {}

And if I remove the “raise”, the controller throws a “can’t modify  
frozen hash” error.

Any idea how I can remove records from the hash prior to saving?

TIA,  
Craig
