Reorganize range.js.

This commit is contained in:
Tobie Langel 2008-09-29 23:07:16 +02:00
parent 23b760865a
commit 314e161c57
1 changed files with 17 additions and 10 deletions

View File

@ -1,27 +1,34 @@
var ObjectRange = Class.create(Enumerable, {
initialize: function(start, end, exclusive) {
function $R(start, end, exclusive) {
return new ObjectRange(start, end, exclusive);
}
var ObjectRange = Class.create(Enumerable, (function() {
function initialize(start, end, exclusive) {
this.start = start;
this.end = end;
this.exclusive = exclusive;
},
}
_each: function(iterator) {
function _each(iterator) {
var value = this.start;
while (this.include(value)) {
iterator(value);
value = value.succ();
}
},
}
include: function(value) {
function include(value) {
if (value < this.start)
return false;
if (this.exclusive)
return value < this.end;
return value <= this.end;
}
});
return {
initialize: initialize,
_each: _each,
include: include
};
})());
var $R = function(start, end, exclusive) {
return new ObjectRange(start, end, exclusive);
};