summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-array-ext
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-array-ext')
-rw-r--r--mrbgems/mruby-array-ext/mrblib/array.rb46
-rw-r--r--mrbgems/mruby-array-ext/src/array.c19
2 files changed, 47 insertions, 18 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
diff --git a/mrbgems/mruby-array-ext/src/array.c b/mrbgems/mruby-array-ext/src/array.c
index d69f0ac44..79dadbee5 100644
--- a/mrbgems/mruby-array-ext/src/array.c
+++ b/mrbgems/mruby-array-ext/src/array.c
@@ -4,7 +4,7 @@
#include "mruby/range.h"
#include "mruby/hash.h"
-/*
+/**
* call-seq:
* ary.assoc(obj) -> new_ary or nil
*
@@ -22,8 +22,9 @@
* a = [ s1, s2, s3 ]
* a.assoc("letters") #=> [ "letters", "a", "b", "c" ]
* a.assoc("foo") #=> nil
+ *
+ * @mrbgem mruby-array-ext
*/
-
static mrb_value
mrb_ary_assoc(mrb_state *mrb, mrb_value ary)
{
@@ -73,7 +74,7 @@ mrb_ary_rassoc(mrb_state *mrb, mrb_value ary)
return mrb_nil_value();
}
-/*
+/**
* call-seq:
* ary.at(index) -> obj or nil
*
@@ -84,8 +85,9 @@ mrb_ary_rassoc(mrb_state *mrb, mrb_value ary)
* a = [ "a", "b", "c", "d", "e" ]
* a.at(0) #=> "a"
* a.at(-1) #=> "e"
+ *
+ * @mrbgem mruby-array-ext
*/
-
static mrb_value
mrb_ary_at(mrb_state *mrb, mrb_value ary)
{
@@ -95,6 +97,10 @@ mrb_ary_at(mrb_state *mrb, mrb_value ary)
return mrb_ary_entry(ary, pos);
}
+/**
+ *
+ * @mrbgem mruby-array-ext
+ */
static mrb_value
mrb_ary_values_at(mrb_state *mrb, mrb_value self)
{
@@ -106,7 +112,7 @@ mrb_ary_values_at(mrb_state *mrb, mrb_value self)
return mrb_get_values_at(mrb, self, RARRAY_LEN(self), argc, argv, mrb_ary_ref);
}
-/*
+/**
* call-seq:
* ary.to_h -> Hash
*
@@ -115,8 +121,9 @@ mrb_ary_values_at(mrb_state *mrb, mrb_value self)
*
* [[:foo, :bar], [1, 2]].to_h
* # => {:foo => :bar, 1 => 2}
+ *
+ * @mrbgem mruby-array-ext
*/
-
static mrb_value
mrb_ary_to_h(mrb_state *mrb, mrb_value ary)
{