From: "Jan E." Date: 2012-04-12T18:15:34+09:00 Subject: Re: ruby v.1.8.6. Expand array class, make combinations Hi, What do you mean by "use newarr"? If you want the method to return the result array, you have to write "return newarr" (or simply "newarr") in the method body: class Array def comby ## Make al unique combinations of 2 elements posmax = (length - 1) newarr = [] for n in 0.. posmax for m in 0.. posmax i1 = self[n] i2 = self[m] if newarr.include? ([i2,i1]) # newarr.push('X') elsif i1 == i2 # newarr.push('X') else newarr.push([i1,i2]) end end end newarr # return the result array end end By the way, I would replace the "for ... in" loops with "upto" iterators. Those or more Ruby-like and have the advantage of not spilling every internal variable. And the inner loop/iterator shouldn't start at 0 but at the next to current index of the outer loop/iterator. Then you can leave out the if statement (assuming the base array is unique): 0.upto posmax do |i| (i + 1).upto posmax do |j| newarr << [self[i], self[j]] end end -- Posted via http://www.ruby-forum.com/.