[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Overloading Array Subtraction operator

Victor 'Zverok' Shepelev

6/10/2007 7:46:00 AM

From: Nicko [mailto:anko.com@gmail.com]
Sent: Sunday, June 10, 2007 10:30 AM
>
>arraydiff = array1 - array2
>--------------
>
>What methods would I have to overload to accomplish this task? I
>could not find an example like this anywhere!

array1 - array2

is just a shorthand for

array1.-(array2)

where "-" is normal method name.

So, you can just do

class Array
def -(other)
...
end
end

--
zverok.