ary.drop_while { |arr| block } â new_aryary.drop_while â Enumerator Instance Public methods Drops elements up to, but not including, the first element for which the block returns nil or false and returns an array containing the remaining elements. If no block is given, an Enumerator is returned instead. See also #take_while a = [1, 2, 3, 4, 5, 0] a.drop_while {|i| i < 3 } #=> [3, 4, 5, 0]
ary.drop(n) â new_ary Instance Public methods Drops first n elements from ary and returns the rest of the elements in an array. If a negative number is given, raises an ArgumentError. See also #take a = [1, 2, 3, 4, 5, 0] a.drop(3) #=> [4, 5, 0]
ary.delete_if { |item| block } â aryary.delete_if â Enumerator Instance Public methods Deletes every element of self for which block evaluates to true. The array is changed instantly every time the block is called, not after the iteration is over. See also #reject! If no block is given, an Enumerator is returned instead. a = [ "a", "b", "c" ] a.delete_if {|x| x >= "b" } #=> ["a"]
ary.delete_at(index) â obj or nil Instance Public methods Deletes the element at the specified index, returning that element, or nil if the index is out of range. See also #slice! a = ["ant", "bat", "cat", "dog"] a.delete_at(2) #=> "cat" a #=> ["ant", "bat", "dog"] a.delete_at(99) #=> nil
ary.delete(obj) â item or nilary.delete(obj) { block } â item or result of block Instance Public methods Deletes all items from self that are equal to obj. Returns the last deleted item, or nil if no matching item is found. If the optional code block is given, the result of the block is returned if the item is not found. (To remove nil elements and get an informative return value, use #compact!) a = [ "a", "b", "b", "b", "c" ] a.delete("b") #=> "b
dclone() Instance Public methods provides a unified clone operation, for REXML::XPathParser to use across multiple Object+ types
ary.cycle(n=nil) { |obj| block } â nilary.cycle(n=nil) â Enumerator Instance Public methods Calls the given block for each element n times or forever if nil is given. Does nothing if a non-positive number is given or the array is empty. Returns nil if the loop has finished without getting interrupted. If no block is given, an Enumerator is returned instead. a = ["a", "b", "c"] a.cycle { |x| puts x } # print, a, b, c, a, b, c,.. forever. a.cycle(2) { |x| puts
ary.count â intary.count(obj) â intary.count { |item| block } â int Instance Public methods Returns the number of elements. If an argument is given, counts the number of elements which equal obj using ===. If a block is given, counts the number of elements for which the block returns a true value. ary = [1, 2, 4, 2] ary.count #=> 4 ary.count(2) #=> 2 ary.count { |x| x%2 == 0 } #=> 3
ary.concat(other_ary) â ary Instance Public methods Appends the elements of other_ary to self. [ "a", "b" ].concat( ["c", "d"] ) #=> [ "a", "b", "c", "d" ] a = [ 1, 2, 3 ] a.concat( [ 4, 5 ] ) a #=> [ 1, 2, 3, 4, 5 ] See also Array#+.
ary.compact! â ary or nil Instance Public methods Removes nil elements from the array. Returns nil if no changes were made, otherwise returns the array. [ "a", nil, "b", nil, "c" ].compact! #=> [ "a", "b", "c" ] [ "a", "b", "c" ].compact! #=> nil
Page 2258 of 2275