summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mrbgems/mruby-enum-ext/mrblib/enum.rb22
1 files changed, 19 insertions, 3 deletions
diff --git a/mrbgems/mruby-enum-ext/mrblib/enum.rb b/mrbgems/mruby-enum-ext/mrblib/enum.rb
index b492ae9af..50eaa6a4d 100644
--- a/mrbgems/mruby-enum-ext/mrblib/enum.rb
+++ b/mrbgems/mruby-enum-ext/mrblib/enum.rb
@@ -548,14 +548,30 @@ module Enumerable
#
def cycle(n=nil, &block)
+ ary = []
if n == nil
- loop {self.each {|val| block.call(val) } }
+ self.each do|*val|
+ ary.push val
+ block.call(*val)
+ end
+ loop do
+ ary.each do|e|
+ block.call(*e)
+ end
+ end
else
- raise TypeError, "expected Integer for 1st argument" unless n.kind_of? Integer
+ unless n.kind_of? Integer
+ raise TypeError, "expected Integer for 1st argument"
+ end
+ self.each do|*val|
+ ary.push val
+ end
count = 0
while count < n
- self.each {|val| block.call(val) }
+ ary.each do|e|
+ block.call(*e)
+ end
count += 1
end
end