(function() {

  this.def_class('Array',DObject,function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function Array(){}; this.__ctor__.prototype = this.prototype; }

    this.prototype["~="] = function(other_ary) {
      var i, item, _len, _primitive;
      if (this.length !== other_ary.length) return false;
      for (i = 0, _len = (this.len ? this.len() : this.length),_primitive = (this instanceof Array || !this.at); i < _len; i++) {
        item = _primitive ? this[i] : this.at(i);
        if (item && item['~=']) {
          if (!item["~="](other_ary[i])) return false;
        } else {
          if (item !== other_ary[i]) return false;
        }
      }
      return true;
    }; __method_added(this,"~=");

    this.prototype["|"] = function(other_ary) {}; __method_added(this,"|");

    this.prototype["&"] = function(other_ary) {}; __method_added(this,"&");

    this.prototype["[]"] = function(index) {
      return this[index];
    }; __method_added(this,"[]");

    this.prototype["[]="] = function(index, value) {
      return this[index] = value;
    }; __method_added(this,"[]=");

    this.prototype["<<"] = function(obj) {
      return this.push(obj);
    }; __method_added(this,"<<");

    this.prototype[">>"] = function(obj) {}; __method_added(this,">>");

    this.prototype.len = function() {
      return this.length;
    }; __method_added(this,"len");

    this.prototype.size = function() {
      return this.length;
    }; __method_added(this,"size");

    this.prototype.last = function() {
      return this[this.length - 1];
    }; __method_added(this,"last");

    this.prototype.first = function() {
      return this[0];
    }; __method_added(this,"first");

    this.prototype["empty!"] = function() {
      this.length = 0;
      return this;
    }; __method_added(this,"empty!");

    this.prototype["any?"] = function() {
      return this.length > 0;
    }; __method_added(this,"any?");

    this.prototype["all?"] = function(sym_or_block) {
      var block, i, l;
      var _this = this;
      i = 0;
      l = this.length;
      block = typeof sym_or_block !== 'string' ? sym_or_block : (function(v) {
        return v[sym_or_block]();
      });
      while (i < l) {
        if (!block(this[i])) return false;
        i++;
      }
      return true;
    }; __method_added(this,"all?");

    this.prototype.max = function() {
      if (this.length) {
        return Math.max.apply(Math, this);
      } else {
        return 0;
      }
    }; __method_added(this,"max");

    this.prototype.min = function() {
      if (this.length) {
        return Math.min.apply(Math, this);
      } else {
        return 0;
      }
    }; __method_added(this,"min");

    this.prototype.count = function(obj_or_block) {}; __method_added(this,"count");

    this.prototype.index = function(obj_or_block) {}; __method_added(this,"index");

    this.prototype.rindex = function(obj_or_block) {}; __method_added(this,"rindex");

    this.prototype.rotate = function(cnt) {
      if (cnt == null) cnt = 1;
    }; __method_added(this,"rotate");

    this.prototype["rotate!"] = function(cnt) {
      if (cnt == null) cnt = 1;
    }; __method_added(this,"rotate!");

    this.prototype.has = function(item) {
      return this.indexOf(item) >= 0;
    }; __method_added(this,"has");

    this.prototype["include?"] = function(item) {
      return this.indexOf(item) >= 0;
    }; __method_added(this,"include?");

    this.prototype.compact = function() {}; __method_added(this,"compact");

    this.prototype["compact!"] = function() {}; __method_added(this,"compact!");

    this.prototype.clone = function() {
      var clone;
      clone = [];
      clone.push.apply(clone, this);
      return clone;
    }; __method_added(this,"clone");

    this.prototype.remove = function(item) {
      var i;
      i = this.indexOf(item);
      if (i >= 0) this.splice(i, 1);
      return this;
    }; __method_added(this,"remove");

    this.prototype.add = function(item, i) {
      if (typeof i === 'object') {
        if (i.after !== void 0) {
          i = this.indexOf(i.after) + 1;
        } else if (i.before !== void 0) {
          i = this.indexOf(i.before);
        }
      }
      if (typeof i === 'number') {
        this.splice(i, 0, item);
      } else {
        i = this.push(item) - 1;
      }
      this.emit('add', item, i);
      return i;
    }; __method_added(this,"add");

    /* Queries a Baz for items.
    @param {number} groupNum Subgroup id to query.
    @param {string|number|null} term An itemName,
        or itemId, or null to search everything.
    */

    this.prototype.move = function(item, opts) {
      var from, to;
      from = this.indexOf(item);
      if (from === -1) return false;
      if (typeof opts === 'object') {
        if (opts.after !== void 0) {
          to = this.indexOf(opts.after) + 1;
        } else if (opts.before !== void 0) {
          to = this.indexOf(opts.before);
        }
      } else {
        to = from + opts;
      }
      to = __scope.Math.max(__scope.Math.min(to, this.size()), 0);
      if (from === to) return false;
      this.splice(from, 1);
      this.splice(to, 0, item);
      this.emit('move', item, to, from);
      return this;
    }; __method_added(this,"move");

    this.prototype.sadd = function(item) {
      if (!this.has(item)) return this.add(item);
    }; __method_added(this,"sadd");

  });

  __scope.Array.prototype.each = __scope.Array.prototype.forEach;

}).call($$base);

