diff options
| author | Seba Gamboa <[email protected]> | 2015-10-14 14:37:47 -0300 |
|---|---|---|
| committer | Seba Gamboa <[email protected]> | 2015-10-20 12:16:47 -0300 |
| commit | 5cdcce8dbddd94ecb9503a0a1d47370c4ef97177 (patch) | |
| tree | 07dae36bc4e2762a8d420fbea2e67b4a087ea260 /mrbgems/mruby-array-ext/mrblib | |
| parent | 84b70886cd9827593810264bf1f068044d5c6986 (diff) | |
| download | mruby-5cdcce8dbddd94ecb9503a0a1d47370c4ef97177.tar.gz mruby-5cdcce8dbddd94ecb9503a0a1d47370c4ef97177.zip | |
Mark core gems with mrbgem tag
Diffstat (limited to 'mrbgems/mruby-array-ext/mrblib')
| -rw-r--r-- | mrbgems/mruby-array-ext/mrblib/array.rb | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb index 35be79339..74b183d3f 100644 --- a/mrbgems/mruby-array-ext/mrblib/array.rb +++ b/mrbgems/mruby-array-ext/mrblib/array.rb @@ -1,4 +1,5 @@ class Array + ## # call-seq: # ary.uniq! -> ary or nil @@ -15,6 +16,7 @@ class Array # c = [["student","sam"], ["student","george"], ["teacher","matz"]] # c.uniq! { |s| s.first } # => [["student", "sam"], ["teacher", "matz"]] # + # @mrbgem mruby-array-ext def uniq!(&block) ary = self.dup result = [] @@ -54,6 +56,7 @@ class Array # b = [["student","sam"], ["student","george"], ["teacher","matz"]] # b.uniq { |s| s.first } # => [["student", "sam"], ["teacher", "matz"]] # + # @mrbgem mruby-array-ext def uniq(&block) ary = self.dup if block @@ -75,6 +78,7 @@ class Array # # [ 1, 1, 2, 2, 3, 3, 4, 5 ] - [ 1, 2, 4 ] #=> [ 3, 3, 5 ] # + # @mrbgem mruby-array-ext def -(elem) raise TypeError, "can't convert #{elem.class} into Array" unless elem.class == Array @@ -95,6 +99,7 @@ class Array # [ "a", "b", "c" ] | [ "c", "d", "a" ] # #=> [ "a", "b", "c", "d" ] # + # @mrbgem mruby-array-ext def |(elem) raise TypeError, "can't convert #{elem.class} into Array" unless elem.class == Array @@ -111,6 +116,7 @@ class Array # # [ 1, 1, 3, 5 ] & [ 1, 2, 3 ] #=> [ 1, 3 ] # + # @mrbgem mruby-array-ext def &(elem) raise TypeError, "can't convert #{elem.class} into Array" unless elem.class == Array @@ -143,6 +149,7 @@ class Array # a = [ 1, 2, [3, [4, 5] ] ] # a.flatten(1) #=> [1, 2, 3, [4, 5]] # + # @mrbgem mruby-array-ext def flatten(depth=nil) ar = [] self.each do |e| @@ -172,6 +179,7 @@ class Array # a = [ 1, 2, [3, [4, 5] ] ] # a.flatten!(1) #=> [1, 2, 3, [4, 5]] # + # @mrbgem mruby-array-ext def flatten!(depth=nil) modified = false ar = [] @@ -199,6 +207,7 @@ class Array # [ "a", nil, "b", nil, "c", nil ].compact # #=> [ "a", "b", "c" ] # + # @mrbgem mruby-array-ext def compact result = self.dup result.compact! @@ -216,6 +225,7 @@ class Array # [ "a", nil, "b", nil, "c" ].compact! #=> [ "a", "b", "c" ] # [ "a", "b", "c" ].compact! #=> nil # + # @mrbgem mruby-array-ext def compact! result = self.select { |e| !e.nil? } if result.size == self.size @@ -226,6 +236,7 @@ class Array end # for efficiency + # @mrbgem mruby-array-ext def reverse_each(&block) return to_enum :reverse_each unless block_given? @@ -238,6 +249,7 @@ class Array end NONE=Object.new + ## # call-seq: # ary.fetch(index) -> obj @@ -260,7 +272,7 @@ class Array # a.fetch(100) { |i| puts "#{i} is out of bounds" } # #=> "100 is out of bounds" # - + # @mrbgem mruby-array-ext def fetch(n=nil, ifnone=NONE, &block) warn "block supersedes default value argument" if !n.nil? && ifnone != NONE && block @@ -310,7 +322,7 @@ class Array # a.fill(1, 2) { |i| i+1 } #=> [0, 2, 3, 27] # a.fill(0..1) { |i| i+1 } #=> [1, 2, 3, 27] # - + # @mrbgem mruby-array-ext def fill(arg0=nil, arg1=nil, arg2=nil, &block) if arg0.nil? && arg1.nil? && arg2.nil? && !block raise ArgumentError, "wrong number of arguments (0 for 1..3)" @@ -394,7 +406,8 @@ class Array # a #=> ["a", "b", "c", "d"] # a.rotate(2) #=> ["c", "d", "a", "b"] # a.rotate(-3) #=> ["b", "c", "d", "a"] - + # + # @mrbgem mruby-array-ext def rotate(count=1) ary = [] len = self.length @@ -425,12 +438,12 @@ class Array # a #=> ["b", "c", "d", "a"] # a.rotate!(2) #=> ["d", "a", "b", "c"] # a.rotate!(-3) #=> ["a", "b", "c", "d"] - + # + # @mrbgem mruby-array-ext def rotate!(count=1) self.replace(self.rotate(count)) end - ## # call-seq: # ary.delete_if { |item| block } -> ary # ary.delete_if -> Enumerator @@ -446,7 +459,8 @@ class Array # # scores = [ 97, 42, 75 ] # scores.delete_if {|score| score < 80 } #=> [97] - + # + # @mrbgem mruby-array-ext def delete_if(&block) return to_enum :delete_if unless block_given? @@ -475,7 +489,8 @@ class Array # See also Enumerable#reject and Array#delete_if. # # If no block is given, an Enumerator is returned instead. - + # + # @mrbgem mruby-array-ext def reject!(&block) return to_enum :reject! unless block_given? @@ -507,7 +522,8 @@ class Array # a = %w{ a b c d } # a.insert(2, 99) #=> ["a", "b", 99, "c", "d"] # a.insert(-2, 1, 2, 3) #=> ["a", "b", 99, "c", 1, 2, 3, "d"] - + # + # @mrbgem mruby-array-ext def insert(idx, *args) idx += self.size + 1 if idx < 0 self[idx, 0] = args @@ -565,7 +581,8 @@ class Array # You must not mix the two modes at a time; the block must always # return either true/false, or always return a number. It is # undefined which value is actually picked up at each iteration. - + # + # @mrbgem mruby-array-ext def bsearch(&block) return to_enum :bsearch unless block_given? @@ -612,7 +629,8 @@ class Array # # scores = [ 97, 42, 75 ] # scores.delete_if {|score| score < 80 } #=> [97] - + # + # @mrbgem mruby-array-ext def delete_if(&block) return to_enum :delete_if unless block_given? @@ -641,7 +659,8 @@ class Array # # a = [1, 2, 3, 4, 5] # a.keep_if { |val| val > 3 } #=> [4, 5] - + # + # @mrbgem mruby-array-ext def keep_if(&block) return to_enum :keep_if unless block_given? @@ -670,7 +689,8 @@ class Array # See also Array#keep_if # # If no block is given, an Enumerator is returned instead. - + # + # @mrbgem mruby-array-ext def select!(&block) return to_enum :select! unless block_given? @@ -694,6 +714,8 @@ class Array # first object for which the block returns +true+. Returns +nil+ if no # match is found. # + # @mrbgem mruby-array-ext + # # ISO 15.2.12.5.14 def index(val=NONE, &block) return to_enum(:find_index, val) if !block && val == NONE |
