mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #2119 from ksss/range-each
Range#each fixnums are special
This commit is contained in:
+13
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user