# How to monkeypatch Hash's \[\]= method, revisted

**URL:** <https://www.ruby-forum.com/t/how-to-monkeypatch-hashs-method-revisted/168205>\
**Category:** Rails\
**Created:** [May 18, 2009, 10:01am UTC](https://www.ruby-forum.com/t/how-to-monkeypatch-hashs-method-revisted/168205 "2009-05-18T10:01:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![darren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@darren](https://www.ruby-forum.com/u/darren)\
**Post date:** [May 18, 2009, 10:01am UTC](https://www.ruby-forum.com/t/how-to-monkeypatch-hashs-method-revisted/168205/1 "2009-05-18T10:01:23Z")

</div>

So google for a solution to this problem and found myself here:

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/eaa34998a74831b4/58b80fe0d4eadb1a?lnk=gst&q=+how+to+monkeypatch+Hash's+[]%3D+method+#58b80fe0d4eadb1a](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/eaa34998a74831b4/58b80fe0d4eadb1a?lnk=gst&q=+how+to+monkeypatch+Hash%27s+%5B%5D%3D+method+#58b80fe0d4eadb1a)

But while reading, and admittedly not quite getting the solution, I  
had a bright moment to balance out the stupid moment, realising that []  
= already has an alias to which you can delegate:

class Hash  
def []= key, value  
store processKey(key), processValue(value)  
end  
end

Hope it helps
