summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-04-25 00:05:12 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-04-25 00:05:12 +0900
commitd95c42eefdc3613aef54fb80dc2a0b49d5107bad (patch)
tree49ed4380287cc7cd1c22e7df9e88ab9e4077fb03
parentf882bc8480f4728052c29b55464c0432a1bb7428 (diff)
parent209bf256aa6a42a23211701e6fbc49285cf91ef6 (diff)
downloadmruby-d95c42eefdc3613aef54fb80dc2a0b49d5107bad.tar.gz
mruby-d95c42eefdc3613aef54fb80dc2a0b49d5107bad.zip
Merge pull request #2119 from ksss/range-each
Range#each fixnums are special
-rw-r--r--mrblib/range.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/mrblib/range.rb b/mrblib/range.rb
index d587cab45..1ec9ac508 100644
--- a/mrblib/range.rb
+++ b/mrblib/range.rb
@@ -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)