diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-14 02:41:22 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-14 02:41:22 +0900 |
| commit | 113ab607846e63c0348758d3e13017e0ea3a45a3 (patch) | |
| tree | 379aa985de0a4c1a148bc693b2207eaf66d44bc3 /mrbgems/mruby-enumerator | |
| parent | 463c5f83c3e5f379d4dd59deb17179915fbaf93b (diff) | |
| download | mruby-113ab607846e63c0348758d3e13017e0ea3a45a3.tar.gz mruby-113ab607846e63c0348758d3e13017e0ea3a45a3.zip | |
mruby-enumerator: move definitions in core_mod.rb to mrblib core
Diffstat (limited to 'mrbgems/mruby-enumerator')
| -rw-r--r-- | mrbgems/mruby-enumerator/mrblib/core_mod.rb | 98 |
1 files changed, 0 insertions, 98 deletions
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 |
