Sha256: 6dd213a0c7fde71f59b92d29bf00d150ff89a7a798e48b543dd7feec8dfe234d

Contents?: true

Size: 471 Bytes

Versions: 3

Compression:

Stored size: 471 Bytes

Contents

require 'facet/array/rotate%21'

class Array

  # Rotates an array's elements from back to front n times.
  #
  #   require 'facet/array/rotate'
  #
  #   [1,2,3].rotate      #=> [3,1,2]
  #   [3,1,2].rotate      #=> [2,3,1]
  #   [3,1,2].rotate      #=> [1,2,3]
  #   [1,2,3].rotate(3)   #=> [1,2,3]
  #
  # A negative parameter reverses the order from front to back.
  #
  #   [1,2,3].rotate(-1)  #=> [2,3,1]
  #
  def rotate(n=1)
    self.dup.rotate!(n)
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

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