From 113ab607846e63c0348758d3e13017e0ea3a45a3 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 14 Mar 2014 02:41:22 +0900 Subject: mruby-enumerator: move definitions in core_mod.rb to mrblib core --- mrbgems/mruby-enumerator/mrblib/core_mod.rb | 98 ----------------------------- 1 file changed, 98 deletions(-) delete mode 100644 mrbgems/mruby-enumerator/mrblib/core_mod.rb (limited to 'mrbgems/mruby-enumerator') diff --git a/mrbgems/mruby-enumerator/mrblib/core_mod.rb b/mrbgems/mruby-enumerator/mrblib/core_mod.rb deleted file mode 100644 index 968cc6ac4..000000000 --- a/mrbgems/mruby-enumerator/mrblib/core_mod.rb +++ /dev/null @@ -1,98 +0,0 @@ -## -# modifying existing methods -## - -# See /mrblib/kernel.rb -module Kernel - def loop - return to_enum :loop unless block_given? - - while(true) - yield - end - rescue => StopIteration - nil - end -end - -# See /mrblib/numeric.rb -module Integral - def times &block - return to_enum :times unless block_given? - - i = 0 - while i < self - block.call i - i += 1 - end - self - end -end - -# See /mrblib/enum.rb -module Enumerable - def collect(&block) - return to_enum :collect unless block_given? - - ary = [] - self.each{|val| - ary.push(block.call(val)) - } - ary - end - alias map collect -end - -# See /mrblib/array.rb -class Array - def each(&block) - return to_enum :each unless block_given? - - idx, length = -1, self.length-1 - while idx < length and length <= self.length and length = self.length-1 - elm = self[idx += 1] - unless elm - if elm == nil and length >= self.length - break - end - end - block.call(elm) - end - self - end -end - -# See /mrblib/hash.rb -class Hash - def each(&block) - return to_enum :each unless block_given? - - self.keys.each { |k| block.call [k, self[k]] } - self - end -end - -# See /mrblib/range.rb -class Range - def each &block - return to_enum :each unless block_given? - - val = self.first - unless val.respond_to? :succ - raise TypeError, "can't iterate" - end - - last = self.last - return self if (val <=> last) > 0 - - while((val <=> last) < 0) - block.call(val) - val = val.succ - end - - if not exclude_end? and (val <=> last) == 0 - block.call(val) - end - self - end -end -- cgit v1.2.3