From 0aa83c503d15d5683f2135d172a02f155498c598 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 27 Sep 2015 00:04:34 +0900 Subject: Enumerable#each_{cons,slice} to return enumerators --- mrbgems/mruby-enum-ext/mrblib/enum.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'mrbgems/mruby-enum-ext') diff --git a/mrbgems/mruby-enum-ext/mrblib/enum.rb b/mrbgems/mruby-enum-ext/mrblib/enum.rb index 6fef0c077..d469f0651 100644 --- a/mrbgems/mruby-enum-ext/mrblib/enum.rb +++ b/mrbgems/mruby-enum-ext/mrblib/enum.rb @@ -116,6 +116,7 @@ module Enumerable raise TypeError, "no implicit conversion of #{n.class} into Integer" unless n.respond_to?(:to_int) raise ArgumentError, "invalid size" if n <= 0 + return to_enum(:each_cons,n) unless block ary = [] n = n.to_int self.each do |*val| @@ -143,6 +144,7 @@ module Enumerable raise TypeError, "no implicit conversion of #{n.class} into Integer" unless n.respond_to?(:to_int) raise ArgumentError, "invalid slice size" if n <= 0 + return to_enum(:each_slice,n) unless block ary = [] n = n.to_int self.each do |*val| -- cgit v1.2.3