bitfield_attribute icon indicating copy to clipboard operation
bitfield_attribute copied to clipboard

Calling field.attributes freezes the Hash

Open dysbulic opened this issue 6 years ago • 0 comments

Why does accessing .attributes freeze the storage?

2.3.3 :013 > u = User.last
2.3.3 :014 > u.header_notify = { comment: false }
 => {:comment=>false}
2.3.3 :015 > u.header_notify.attributes
 => {:add_project=>true, :comment=>true, :reply=>false, :like=>true, :follow=>true, :mention=>true}
2.3.3 :016 > u.header_notify = { comment: false }
RuntimeError: can't modify frozen Hash

I suppose it is to prevent modification, but wouldn't .dup be better?

dysbulic avatar May 22 '18 19:05 dysbulic