diff options
| author | Seba Gamboa <[email protected]> | 2015-10-21 14:31:13 -0300 |
|---|---|---|
| committer | Seba Gamboa <[email protected]> | 2015-10-21 14:31:13 -0300 |
| commit | 25c8e9536530afa72bacb78702a7a6d132c354f3 (patch) | |
| tree | fc8c2b24814d4c7a8a994390c6ceb859ceae87ca /mrbgems/mruby-enum-ext/mrblib/enum.rb | |
| parent | 13b552538af9e9794398e4a4177ba1cea04cccca (diff) | |
| download | mruby-25c8e9536530afa72bacb78702a7a6d132c354f3.tar.gz mruby-25c8e9536530afa72bacb78702a7a6d132c354f3.zip | |
Revert "Mark core gems with mrbgem tag"
This reverts commit 5cdcce8dbddd94ecb9503a0a1d47370c4ef97177.
Diffstat (limited to 'mrbgems/mruby-enum-ext/mrblib/enum.rb')
| -rw-r--r-- | mrbgems/mruby-enum-ext/mrblib/enum.rb | 59 |
1 files changed, 21 insertions, 38 deletions
diff --git a/mrbgems/mruby-enum-ext/mrblib/enum.rb b/mrbgems/mruby-enum-ext/mrblib/enum.rb index b41eaaf1f..ed1943f30 100644 --- a/mrbgems/mruby-enum-ext/mrblib/enum.rb +++ b/mrbgems/mruby-enum-ext/mrblib/enum.rb @@ -1,5 +1,7 @@ +## +# Enumerable +# module Enumerable - ## # call-seq: # enum.drop(n) -> array @@ -9,8 +11,7 @@ module Enumerable # # a = [1, 2, 3, 4, 5, 0] # a.drop(3) #=> [4, 5, 0] - # - # @mrbgem mruby-enum-ext + def drop(n) raise TypeError, "no implicit conversion of #{n.class} into Integer" unless n.respond_to?(:to_int) raise ArgumentError, "attempt to drop negative size" if n < 0 @@ -34,8 +35,7 @@ module Enumerable # # a = [1, 2, 3, 4, 5, 0] # a.drop_while {|i| i < 3 } #=> [3, 4, 5, 0] - # - # @mrbgem mruby-enum-ext + def drop_while(&block) return to_enum :drop_while unless block @@ -55,8 +55,7 @@ module Enumerable # # a = [1, 2, 3, 4, 5, 0] # a.take(3) #=> [1, 2, 3] - # - # @mrbgem mruby-enum-ext + def take(n) raise TypeError, "no implicit conversion of #{n.class} into Integer" unless n.respond_to?(:to_int) raise ArgumentError, "attempt to take negative size" if n < 0 @@ -83,7 +82,6 @@ module Enumerable # a = [1, 2, 3, 4, 5, 0] # a.take_while {|i| i < 3 } #=> [1, 2] # - # @mrbgem mruby-enum-ext def take_while(&block) return to_enum :take_while unless block @@ -112,8 +110,7 @@ module Enumerable # [6, 7, 8] # [7, 8, 9] # [8, 9, 10] - # - # @mrbgem mruby-enum-ext + def each_cons(n, &block) raise TypeError, "no implicit conversion of #{n.class} into Integer" unless n.respond_to?(:to_int) raise ArgumentError, "invalid size" if n <= 0 @@ -140,8 +137,7 @@ module Enumerable # [4, 5, 6] # [7, 8, 9] # [10] - # - # @mrbgem mruby-enum-ext + def each_slice(n, &block) raise TypeError, "no implicit conversion of #{n.class} into Integer" unless n.respond_to?(:to_int) raise ArgumentError, "invalid slice size" if n <= 0 @@ -170,7 +166,6 @@ module Enumerable # # (1..6).group_by {|i| i%3} #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]} # - # @mrbgem mruby-enum-ext def group_by(&block) return to_enum :group_by unless block @@ -192,8 +187,7 @@ module Enumerable # values in <i>enum</i> through the given block. # # If no block is given, an enumerator is returned instead. - # - # @mrbgem mruby-enum-ext + def sort_by(&block) return to_enum :sort_by unless block @@ -220,8 +214,6 @@ module Enumerable # Returns the first element, or the first +n+ elements, of the enumerable. # If the enumerable is empty, the first form returns <code>nil</code>, and the # second form returns an empty array. - # - # @mrbgem mruby-enum-ext def first(n=NONE) if n == NONE self.each do |*val| @@ -250,8 +242,6 @@ module Enumerable # If an argument is given, the number of items in +enum+ that # are equal to +item+ are counted. If a block is given, it # counts the number of elements yielding a true value. - # - # @mrbgem mruby-enum-ext def count(v=NONE, &block) count = 0 if block @@ -284,8 +274,6 @@ module Enumerable # # [1, 2, 3, 4].flat_map { |e| [e, -e] } #=> [1, -1, 2, -2, 3, -3, 4, -4] # [[1, 2], [3, 4]].flat_map { |e| e + [100] } #=> [1, 2, 100, 3, 4, 100] - # - # @mrbgem mruby-enum-ext def flat_map(&block) return to_enum :flat_map unless block @@ -313,8 +301,7 @@ module Enumerable # If no block is given, an enumerator is returned instead. # # %w[albatross dog horse].max_by {|x| x.length } #=> "albatross" - # - # @mrbgem mruby-enum-ext + def max_by(&block) return to_enum :max_by unless block @@ -348,8 +335,7 @@ module Enumerable # If no block is given, an enumerator is returned instead. # # %w[albatross dog horse].min_by {|x| x.length } #=> "dog" - # - # @mrbgem mruby-enum-ext + def min_by(&block) return to_enum :min_by unless block @@ -385,8 +371,7 @@ module Enumerable # a = %w(albatross dog horse) # a.minmax #=> ["albatross", "horse"] # a.minmax { |a, b| a.length <=> b.length } #=> ["dog", "albatross"] - # - # @mrbgem mruby-enum-ext + def minmax(&block) max = nil min = nil @@ -424,8 +409,7 @@ module Enumerable # If no block is given, an enumerator is returned instead. # # %w(albatross dog horse).minmax_by { |x| x.length } #=> ["dog", "albatross"] - # - # @mrbgem mruby-enum-ext + def minmax_by(&block) return to_enum :minmax_by unless block @@ -468,8 +452,7 @@ module Enumerable # [].none? #=> true # [nil, false].none? #=> true # [nil, true].none? #=> false - # - # @mrbgem mruby-enum-ext + def none?(&block) if block self.each do |*val| @@ -499,7 +482,7 @@ module Enumerable # [nil, true, 99].one? #=> false # [nil, true, false].one? #=> true # - # @mrbgem mruby-enum-ext + def one?(&block) count = 0 if block @@ -530,7 +513,7 @@ module Enumerable # (1..10).each_with_object([]) { |i, a| a << i*2 } # #=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] # - # @mrbgem mruby-enum-ext + def each_with_object(obj=nil, &block) raise ArgumentError, "wrong number of arguments (0 for 1)" if obj.nil? @@ -557,7 +540,7 @@ module Enumerable # 2 # 1 # - # @mrbgem mruby-enum-ext + def reverse_each(&block) return to_enum :reverse_each unless block @@ -589,7 +572,7 @@ module Enumerable # a.cycle { |x| puts x } # print, a, b, c, a, b, c,.. forever. # a.cycle(2) { |x| puts x } # print, a, b, c, a, b, c. # - # @mrbgem mruby-enum-ext + def cycle(n=nil, &block) return to_enum(:cycle, n) if !block && n.nil? @@ -638,7 +621,7 @@ module Enumerable # (1..100).find_index { |i| i % 5 == 0 and i % 7 == 0 } #=> 34 # (1..100).find_index(50) #=> 49 # - # @mrbgem mruby-enum-ext + def find_index(val=NONE, &block) return to_enum(:find_index, val) if !block && val == NONE @@ -668,7 +651,7 @@ module Enumerable # <code>enum#size</code>. If the size of any argument is less than # <code>enum#size</code>, <code>nil</code> values are supplied. # - # @mrbgem mruby-enum-ext + def zip(*arg) ary = [] arg = arg.map{|a|a.to_a} @@ -697,7 +680,7 @@ module Enumerable # %i[hello world].each_with_index.to_h # # => {:hello => 0, :world => 1} # - # @mrbgem mruby-enum-ext + def to_h h = {} self.each do |*v| |
