Merge pull request #2119 from ksss/range-each

Range#each fixnums are special
This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-04-25 00:05:12 +09:00
+13 -1
View File
@@ -13,11 +13,23 @@ class Range
return to_enum :each unless block_given?
val = self.first
last = self.last
if val.kind_of?(Fixnum) && last.kind_of?(Fixnum) # fixnums are special
lim = last
lim += 1 unless exclude_end?
i = val
while i < lim
block.call(i)
i += 1
end
return self
end
unless val.respond_to? :succ
raise TypeError, "can't iterate"
end
last = self.last
return self if (val <=> last) > 0
while((val <=> last) < 0)