class Range
def ==(other)
def ==(other) %x{ if (!other._isRange) { return false; } return #{self}.exclude === other.exclude && #{self}.begin == other.begin && #{self}.end == other.end; } end
def ===(obj)
def ===(obj) `return obj >= #{self}.begin && (#{self}.exclude ? obj < #{self}.end : obj <= #{self}.end)` end
def cover?(value)
def cover?(value) `#{self}.begin` <= value && value <= (exclude_end? ? `#{self}.end` - 1 : `#{self}.end`) end
def each(&block)
def each(&block) current = min while current != max yield current current = current.succ end yield current unless exclude_end? self end
def eql?(other)
def eql?(other) return false unless Range === other exclude_end? == other.exclude_end? && `#{self}.begin`.eql?(other.begin) && `#{self}.end`.eql?(other.end) end
def exclude_end?
def exclude_end? `#{self}.exclude` end
def include?(val)
def include?(val) `return obj >= #{self}.begin && obj <= #{self}.end` end
def initialize(min, max, exclude = false)
def initialize(min, max, exclude = false) @begin = min @end = max @exclude = exclude end
def step(n = 1)
def step(n = 1) raise NotImplementedError end
def to_s
def to_s `#{self}.begin + (#{self}.exclude ? '...' : '..') + #{self}.end` end