diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-27 14:35:07 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-27 14:35:07 +0900 |
| commit | b5cb8284ba502cbd5d80f35f5ec892496468f4ff (patch) | |
| tree | 3a616ca4eefd19bb7185b157fa96e455a7b526c3 | |
| parent | fc51781402d35f182772d810f15705899d366f03 (diff) | |
| download | mruby-b5cb8284ba502cbd5d80f35f5ec892496468f4ff.tar.gz mruby-b5cb8284ba502cbd5d80f35f5ec892496468f4ff.zip | |
Enumerable#zip to use enumerator if mruby-enumerator gem is available
| -rw-r--r-- | mrbgems/mruby-enumerator/mrblib/enumerator.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/mrbgems/mruby-enumerator/mrblib/enumerator.rb b/mrbgems/mruby-enumerator/mrblib/enumerator.rb index 17a650d6c..1494c02c5 100644 --- a/mrbgems/mruby-enumerator/mrblib/enumerator.rb +++ b/mrbgems/mruby-enumerator/mrblib/enumerator.rb @@ -607,3 +607,28 @@ module Kernel end alias :enum_for :to_enum end + +module Enumerable + # use Enumerator to use inifite sequence + def zip(*arg) + ary = [] + arg = arg.map{|a|a.each} + i = 0 + self.each do |*val| + a = [] + a.push(val.__svalue) + idx = 0 + while idx < arg.size + begin + a.push(arg[idx].next) + rescue StopIteration + a.push(nil) + end + idx += 1 + end + ary.push(a) + i += 1 + end + ary + end +end |
