From: Siep Korteling Date: 2008-05-30T07:05:40+09:00 Subject: Re: Quickie: Monkey patching Array Leon Bogaert wrote: > Hi all, > > A quick question: is it possible to monkey patch the Array [] method in > ruby? > > I tried: > > class Array > def []=(elem) > raise 'Yesss... It works!' > end > end > > But that didn't work. I tried patching the Kernel module but that didn't > have any effect either. Is the [] hidden else somewhere? Or do I have to > use rubinius for that? :) > > Thanks! > > Leon You redefined the []= method, not the [] method. class Array def [](elem) # just get rid of the "=" raise 'Yesss... It works!' end end groeten, Siep -- Posted via http://www.ruby-forum.com/.