Method: Array#rotate

Defined in:
lib/core/facets/array/rotate.rb

#rotate(n = 1) ⇒ Object

Rotates an array’s elements from back to front n times.

[1,2,3].rotate      #=> [2,3,1]
[2,3,1].rotate      #=> [3,1,2]
[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)  #=> [3,1,2]

CREDIT: Florian Gross, Thomas Sawyer



19
20
21
# File 'lib/core/facets/array/rotate.rb', line 19

def rotate(n=1)
  self.dup.rotate!(n)
end