From: Reidmix Date: 2008-05-30T08:55:54+09:00 Subject: Re: Quickie: Monkey patching Array --0-540607005-1212104928=:56590 Content-Type: text/plain; charset=us-ascii you are just assigning a to an array literal This is equivalent to a = Array.new(['one','two','three']) Like Siep said, array access a[0] will raise the error. r ----- Original Message ---- From: Siep Korteling To: ruby-talk ML Sent: Thursday, May 29, 2008 3:28:45 PM Subject: Re: Quickie: Monkey patching Array Leon Bogaert wrote: > I know it's bad behaviour :) But I'm just fiddling with ruby. > > class Array > def [](elem) # just get rid of the "=" > raise 'Yesss... It works!' > end > end > > a = ['one', 'two', 'three'] > p a > > Didn't work also. It just prints: ["one", "two", "three"] try p a[0] [] is just a method. You chanced it. To verify if your change works, you 'll have to use the [] method. If this is not what you want, what outcome did you expect? regards, Siep -- Posted via http://www.ruby-forum.com/. --0-540607005-1212104928=:56590--