All pastes #624561 Raw Edit

Mine

public text v1 · immutable
·published 2007-07-18 11:27 UTC
rendered paste body
/*
 * Checks if the current Hash is a complete subset of the given Hash.
 * It is a subset IFF every key of the current hash is in the given hash and
 * every value of that key equals the value of the same key in the other hash.
 */
Hash.prototype.subset = function(h2)
{
        return this.all(function(entry) {
                var myval = entry[1];
                var theirval = h2[entry[0]];
                if (theirval && (myval instanceof Array) || (myval instanceof Hash))
                        return myval.subset(theirval);
                else
                        return myval == theirval;
        });
}

/* Subset for Enumerable */
Object.extend(Enumerable, {subset : function(a2)
{
        return this.all(function(x) { return a2.include(x); });
}});
Array.prototype.subset = Enumerable.subset;