# Overloading prefix operators

**URL:** <https://www.ruby-forum.com/t/overloading-prefix-operators/77565>\
**Category:** Ruby\
**Created:** [November 28, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/overloading-prefix-operators/77565 "2006-11-28T21:30:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [November 28, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/overloading-prefix-operators/77565/1 "2006-11-28T21:30:39Z")

</div>

Okay, so “operator overloading” is wonderfully trivial and natural in  
Ruby but it just occured to me that I have no idea how to change the  
behaviour of prefix operators like negate, “-x”, where x is an object…  
How does one do this?  
Thank you…

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [November 28, 2006, 9:34pm UTC](https://www.ruby-forum.com/t/overloading-prefix-operators/77565/2 "2006-11-28T21:34:40Z")

</div>

def -@  
#do stuff here  
end

On 11/28/06, Just Another Victim of the Ambient M. \<

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [November 29, 2006, 3:07am UTC](https://www.ruby-forum.com/t/overloading-prefix-operators/77565/3 "2006-11-29T03:07:38Z")

</div>

Just Another Victim of the Ambient M. wrote:

> Okay, so “operator overloading” is wonderfully trivial and natural in  
> Ruby but it just occured to me that I have no idea how to change the  
> behaviour of prefix operators like negate, “-x”, where x is an object…

Look in the table here:  
[http://phrogz.net/ProgrammingRuby/language.html#operatorexpressions](http://phrogz.net/ProgrammingRuby/language.html#operatorexpressions)
