From: Stefano Crocco Date: 2012-04-20T16:37:56+09:00 Subject: Re: How to override []= array method? Il giorno Fri, 20 Apr 2012 16:22:07 +0900 "Gaurav C." ha scritto: > My class is defined as, > > class Memory < Array > > and I need to override the []= method. > I tried something like, > > def []=(address, value) > self[address] = Word.new(value) > end > > which causes an infinite loop of course: 'stack level too deep'. > How to do it right? > Before defining the new method use alias_method to create a copy of the original one with a different name: class Memory < Array alias_method :set_element, :[]= def []= address, value set_element address, value end end I hope this helps Stefano