# Operator Overloading \<\<

**URL:** <https://rubytalk.org/t/operator-overloading/21223>\
**Category:** ruby-talk\
**Created:** [30 September 2005 00:17 UTC](https://rubytalk.org/t/operator-overloading/21223 "2005-09-30T00:17:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Sheppard](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@Daniel\_Sheppard](https://rubytalk.org/u/Daniel_Sheppard)\
**Post date:** [30 September 2005 00:17 UTC](https://rubytalk.org/t/operator-overloading/21223/1 "2005-09-30T00:17:25Z")

</div>

class Monkey \< Array  
&nbsp;&nbsp;alias :\_\_old\_add :\<\<  
&nbsp;&nbsp;def \<\<(thing)  
&nbsp;&nbsp;&nbsp;&nbsp;puts "I got #{thing}"  
&nbsp;&nbsp;&nbsp;&nbsp;\_\_old\_add(thing)  
&nbsp;&nbsp;end  
end

> **···**
>
> -----Original Message-----  
> From: [matt.hulse@gmail.com](mailto:matt.hulse@gmail.com) [[mailto:matt.hulse@gmail.com](mailto:matt.hulse@gmail.com)]  
> Sent: Friday, 30 September 2005 9:12 AM  
> To: ruby-talk ML  
> Subject: Operator Overloading \<\<
> 
> 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.
> 
> Thanks in advance!
> 
> Matt  
> [matt.hulse@gmail.com](mailto:matt.hulse@gmail.com)
> 
> #####################################################################################  
> This email has been scanned by MailMarshal, an email content filter.  
> #####################################################################################
