summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-04-03 20:19:54 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-04-03 20:19:54 +0900
commit653ddd6d3e8da23b0c7a7e85a199ae32486bdbba (patch)
tree782f40ad2da0c54d07adbd41df9f7cb9409a3a08
parent83a1e7122b5cb8fc22ddcef91241daabf98b1261 (diff)
downloadmruby-653ddd6d3e8da23b0c7a7e85a199ae32486bdbba.tar.gz
mruby-653ddd6d3e8da23b0c7a7e85a199ae32486bdbba.zip
downto, upto, step to return Enumerator
-rw-r--r--mrblib/numeric.rb6
-rw-r--r--src/string.c2
2 files changed, 7 insertions, 1 deletions
diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb
index 034019e8b..5be3c90fc 100644
--- a/mrblib/numeric.rb
+++ b/mrblib/numeric.rb
@@ -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)
diff --git a/src/string.c b/src/string.c
index 439cb5409..e5aac98b7 100644
--- a/src/string.c
+++ b/src/string.c
@@ -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)