Reorganize range.js.
This commit is contained in:
parent
23b760865a
commit
314e161c57
27
src/range.js
27
src/range.js
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue