Method: Array#rotate
- Defined in:
- lib/ludy/array/rotate.rb
#rotate(n = 1) ⇒ Object
rotate right with size. if the size is negative, rotate left.
[1,2,3].rotate
=> [2,3,1]
[1,2,3].rotate -1
=> [3,1,2]
[1,2,3].rotate 2
=> [3,1,2]
13 14 15 16 |
# File 'lib/ludy/array/rotate.rb', line 13 def rotate n = 1 return self if empty? or n == 0 self[n..-1] + self[0...n] end |