From: Jean-Julien Fleck Date: 2010-08-22T01:27:59+09:00 Subject: Re: A small problem for arrays 2010/8/21 Unc88 Unc88 : > Can do the subtraction of arrays without using the operator "-"? > Is there a standard method in the class Array? "-" *is* a standard method of class Array. The apparent "operator" behavior is just syntaxic sugar added on it: >> a1 = (1..10).to_a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >> a2 = (5..7).to_a => [5, 6, 7] >> a1.-(a2) => [1, 2, 3, 4, 8, 9, 10] Last line call "-" method of object "a1" with object "a2" as an argument. ~> ri Array.- ---------------------------------------------------------------- Array#- array - other_array -> an_array ------------------------------------------------------------------------ Array Difference---Returns a new array that is a copy of the original array, removing any items that also appear in other_array. (If you need set-like behavior, see the library class Set.) [ 1, 1, 2, 2, 3, 3, 4, 5 ] - [ 1, 2, 4 ] #=> [ 3, 3, 5 ] Cheers, -- JJ Fleck PCSI1 Lycée Kléber