facf0c92e0
Red Bear OS is a full fork. All sources must be available from git clone with zero network access. Removed gitignore rules that excluded fetched source trees under recipes/*/source/, local/recipes/kde/*/source/, local/recipes/qt/*/source/, and vendor source trees. Build artifacts (target/, build/, source.tar, *.o, *.so) remain excluded. 127291 files added — kernel, relibc, base, bootloader, pkgar, all KDE/Qt frameworks, mesa, wayland, DRM drivers, and every other recipe source.
98 lines
1.9 KiB
Ruby
98 lines
1.9 KiB
Ruby
##
|
|
# Range
|
|
#
|
|
# ISO 15.2.14
|
|
class Range
|
|
##
|
|
# Range is enumerable
|
|
#
|
|
# ISO 15.2.14.3
|
|
include Enumerable
|
|
|
|
##
|
|
# Calls the given block for each element of +self+
|
|
# and pass the respective element.
|
|
#
|
|
# ISO 15.2.14.4.4
|
|
def each(&block)
|
|
return to_enum :each unless block
|
|
|
|
val = self.begin
|
|
last = self.end
|
|
|
|
if val.kind_of?(Integer) && last.nil?
|
|
i = val
|
|
while true
|
|
block.call(i)
|
|
i += 1
|
|
end
|
|
return self
|
|
end
|
|
|
|
if val.kind_of?(String) && last.nil?
|
|
if val.respond_to? :__upto_endless
|
|
return val.__upto_endless(&block)
|
|
else
|
|
str_each = true
|
|
end
|
|
end
|
|
|
|
if val.kind_of?(Integer) && last.kind_of?(Integer) # integers are special
|
|
lim = last
|
|
lim += 1 unless exclude_end?
|
|
i = val
|
|
while i < lim
|
|
block.call(i)
|
|
i += 1
|
|
end
|
|
return self
|
|
end
|
|
|
|
if val.kind_of?(String) && last.kind_of?(String) # strings are special
|
|
if val.respond_to? :upto
|
|
return val.upto(last, exclude_end?, &block)
|
|
else
|
|
str_each = true
|
|
end
|
|
end
|
|
|
|
raise TypeError, "can't iterate" unless val.respond_to? :succ
|
|
|
|
return self if (val <=> last) > 0
|
|
|
|
while (val <=> last) < 0
|
|
block.call(val)
|
|
val = val.succ
|
|
if str_each
|
|
break if val.size > last.size
|
|
end
|
|
end
|
|
|
|
block.call(val) if !exclude_end? && (val <=> last) == 0
|
|
self
|
|
end
|
|
|
|
# redefine #hash 15.3.1.3.15
|
|
def hash
|
|
h = first.hash ^ last.hash
|
|
h += 1 if self.exclude_end?
|
|
h
|
|
end
|
|
|
|
##
|
|
# call-seq:
|
|
# rng.to_a -> array
|
|
# rng.entries -> array
|
|
#
|
|
# Returns an array containing the items in the range.
|
|
#
|
|
# (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7]
|
|
# (1..).to_a #=> RangeError: cannot convert endless range to an array
|
|
def to_a
|
|
a = __num_to_a
|
|
return a if a
|
|
super
|
|
end
|
|
alias entries to_a
|
|
end
|