Skip to content
Permalink
Browse files

Merge pull request #547 from kostya/rotate

Array#rotate
  • Loading branch information
alex committed Mar 29, 2013
2 parents b4720cf + a44ab8d commit abd90baa79fe1cbb788b99e65a8c733c67e9adb6
Showing with 21 additions and 14 deletions.
  1. +5 −0 lib-topaz/array.rb
  2. +0 −14 spec/tags/core/array/rotate_tags.txt
  3. +16 −0 topaz/objects/arrayobject.py
@@ -304,4 +304,9 @@ def reverse_each(&block)
end
return self
end

def rotate(n = 1)
Array.new(self).rotate!(n)
end

end

This file was deleted.

@@ -286,3 +286,19 @@ def method_reverse_i(self, space):
self.items_w.reverse()
return self

@classdef.method("rotate!", n="int")
@check_frozen()
def method_rotate_i(self, space, n=1):
length = len(self.items_w)
if length == 0:
return self
if abs(n) >= length:
n %= length
if n < 0:
n += length
if n == 0:
return self
assert n >= 0
self.items_w.extend(self.items_w[:n])
del self.items_w[:n]
return self

0 comments on commit abd90ba

Please sign in to comment.