8 # Calls the given block for each element of +self+
9 # and pass the respective element.
13 return to_enum :each unless block_given?
15 idx, length = -1, self.length-1
16 while idx < length and length <= self.length and length = self.length-1
19 if elm == nil and length >= self.length
29 # Calls the given block for each element of +self+
30 # and pass the index of the respective element.
33 def each_index(&block)
34 return to_enum :each_index unless block_given?
45 # Calls the given block for each element of +self+
46 # and pass the respective element. Each element will
47 # be replaced by the resulting values.
51 return to_enum :collect! unless block_given?
54 self[idx] = block.call(self[idx])
66 # Private method for Array creation.
69 def initialize(size=0, obj=nil, &block)
70 raise TypeError, "expected Integer for 1st argument" unless size.kind_of? Integer
71 raise ArgumentError, "negative array size" if size < 0
75 self[size - 1] = nil # allocate
79 self[idx] = (block)? block.call(idx): obj
88 # Delete element with index +key+
89 def delete(key, &block)
90 while i = self.index(key)
94 if ret == nil && block
101 # internal method to convert multi-value to single value
115 # Array is enumerable
121 # Sort all elements and replace +self+ with these
124 self.replace(self.sort(&block))