lib/sarah.rb in sarah-2.2.0 vs lib/sarah.rb in sarah-3.0.0

- old
+ new

@@ -58,15 +58,15 @@ # :nsq, :rnd, or :all. # # @author Brian Katzung (briank@kappacs.com), Kappa Computer Solutions, LLC # @copyright 2013-2014 Brian Katzung and Kappa Computer Solutions, LLC # @license MIT License -# @version 2.2.0 +# @version 3.0.0 class Sarah - VERSION = "2.2.0" + VERSION = "3.0.0" # Private attributes: # seq [Array] An array of (zero-origin) sequential values. # spr [Hash] A hash of (typically sparse) integer-keyed values. If # there are any negatively-keyed values (in :actual negative mode), @@ -201,17 +201,18 @@ # #* (replicate or join) is not implemented. # Return a new Sarah that is the concatenation of this one and # another object. # - # (#+ alias since 2.0.0) + # Note: #concat was incorrectly aliased to #+ in 2.x.x. #concat is + # actually an alias for #append!. + # + # @since 2.0.0 def + (other) new_similar(:from => self).append!(other) end - alias_method :concat, :+ - # Compute the array difference with another object. # # Random-access hash values are only removed when both keys and values # match. # @@ -234,14 +235,11 @@ # @param vlist [Array] A list of values to push (append). # @return [Sarah] def << (*vlist) if !@spr.empty? # Sparse push - vlist.each do |value| - self[@ary_next] = value - @ary_next += 1 - end + vlist.each { |value| self[@ary_next] = value } else # Sequential push @seq.push *vlist @ary_next = @seq.size end @@ -333,10 +331,12 @@ alias_method :store, :[]= # Append arrays or Sarahs and merge hashes. # + # (#concat alias since 3.0.0) + # # @param ahlist [Array<Array, Hash, Sarah>] The structures to append. # @return [Sarah] def append! (*ahlist) ahlist.each do |ah| if ah.is_a? Sarah @@ -349,10 +349,12 @@ end end self end + alias_method :concat, :append! + # Return the first associated array. See Array#assoc and Hash#assoc. # The result is always in Array#assoc format. # # @param which [:all|:ary|:seq|:spr|:rnd] Which elements to search. # @return [Array|nil] @@ -383,11 +385,9 @@ @seq, @spr, @ary_first, @ary_next = [], {}, 0, 0 end case which when :all, :rnd then @rnd = {} end self end - - # #collect and #collect! are not implemented, but see #ary_collect!. # Collect (map) in-place. The block (required) is passed the current # value and the index/key (in that order). The return value of the # block becomes the new value. #