Sha256: 3c0db7c50741171db03d2b1f7cf79c119f7bd53e834cb550cdebcd9af922f56a

Contents?: true

Size: 324 Bytes

Versions: 3

Compression:

Stored size: 324 Bytes

Contents

class Array

  # Same as #rotate, but acts in place.
  #
  #   require 'facet/array/rotate'
  #
  #   a = [1,2,3]
  #   a.rotate
  #   a  #=> [3,1,2]
  #
  def rotate!(n=1)
    n = n.to_i
    return self if n == 0
    if n > 1
      n.times{ unshift(pop) }
    else
      n.times{ push(shift) }
    end
    self
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-0.7.0 lib/facet/array/rotate%21.rb
facets-0.7.1 lib/facet/array/rotate%21.rb
facets-0.7.2 lib/facet/array/rotate%21.rb