downto, upto, step to return Enumerator

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-04-03 20:19:54 +09:00
parent 83a1e7122b
commit 653ddd6d3e
2 changed files with 7 additions and 1 deletions
+6
View File
@@ -45,6 +45,8 @@ module Integral
#
# ISO 15.2.8.3.15
def downto(num, &block)
return to_enum(:downto, num) unless block_given?
i = self.to_i
while(i >= num)
block.call(i)
@@ -84,6 +86,8 @@ module Integral
#
# ISO 15.2.8.3.27
def upto(num, &block)
return to_enum(:upto, num) unless block_given?
i = self.to_i
while(i <= num)
block.call(i)
@@ -97,6 +101,8 @@ module Integral
# incremented by +step+ (default 1).
#
def step(num, step=1, &block)
return to_enum(:step, num, step) unless block_given?
i = if num.kind_of? Float then self.to_f else self end
while(i <= num)
block.call(i)
+1 -1
View File
@@ -754,7 +754,7 @@ mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n)
else if (m < 1) {
return 0;
}
else if (m == 1) {
else if (m == 1) {
const unsigned char *ys = y, *ye = ys + n;
for (; y < ye; ++y) {
if (*x == *y)