From: Bob Hutchison Date: 2005-09-30T09:20:20+09:00 Subject: Re: Operator Overloading << Hi, On Sep 29, 2005, at 7:11 PM, matt.hulse@gmail.com wrote: > Is there a way to overload '<<' in the Array class? > > Or perhaps there's a better approach to my problem. I have a class > that inherits from Array. I want the user to be able to use my class > just like a standard array. However, I want to be able to force some > code to run every time a user of my class appends a new item. I was > able to overload the '+' operator to do this but it doesn't fit with > standard array usage. I'm not sure what you mean by overloading. You don't mean like this?... class MyArray < Array def <<(v) puts "before #{v}: #{self.inspect}" super(v) puts "after #{v}: #{self.inspect}" return self end end a = MyArray.new a << 1 << 2 << 3 p a Cheers, Bob > > Thanks in advance! > > Matt > matt.hulse@gmail.com > > > ---- Bob Hutchison -- blogs at Recursive Design Inc. -- Raconteur --