From: Joel VanderWerf Date: 2004-11-16T08:26:07+09:00 Subject: Re: "The Ruby Way" and adding methods to base classes in libraries Tim Bates wrote: > Joel VanderWerf wrote: > >>> So, what's the right way to handle this situation? >> >> >> >> You could define this method in a module and use Object#extend to give >> that functionality to particular arrays. > > > The other way to deal with this would be to create a new class that > inherits from Array: > > class SuperSetArray < Array # or some other, better name > def first_superset_of(*arrays) > arrays.detect do |array| > self.detect do |element| > not array.include?(element) ? false : true > end > end > end > end This is useful, but when an Array gets returned from, say, collect, it's not of this class, so you may still want to extend with a module that defines the same method.