Module: Tins::Rotate

Included in:
Array
Defined in:
lib/tins/rotate.rb

Instance Method Summary collapse

Instance Method Details

#rotate(n = 1) ⇒ Object



12
13
14
# File 'lib/tins/rotate.rb', line 12

def rotate(n = 1)
  clone.rotate!(n)
end

#rotate!(n = 1) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/tins/rotate.rb', line 3

def rotate!(n = 1)
  if n >= 0
    n.times { push shift }
  else
    (-n).times { unshift pop }
  end
  self
end