Skip to content
Permalink
Browse files

Merge pull request #651 from kostya/insert

Array#insert
  • Loading branch information
alex committed Apr 21, 2013
2 parents 6ffe810 + 64badca commit dbce6f2ae4e5e5ac6ebaac3d3dbbd7330aeb3a96
Showing with 23 additions and 12 deletions.
  1. +0 −12 spec/tags/core/array/insert_tags.txt
  2. +23 −0 topaz/objects/arrayobject.py

This file was deleted.

@@ -323,3 +323,26 @@ def method_rotate_i(self, space, n=1):
self.items_w.extend(self.items_w[:n])
del self.items_w[:n]
return self

@classdef.method("insert", i="int")
@check_frozen()
def method_insert(self, space, i, args_w):
if not args_w:
return self
length = len(self.items_w)
if i > length:
for _ in xrange(i - length):
self.items_w.append(space.w_nil)
self.items_w.extend(args_w)
return self
if i < 0:
if i < -length - 1:
raise space.error(space.w_IndexError,
"index %d too small for array; minimum: %d" % (i + 1, -length))
i += length + 1
assert i >= 0
j = i
for e in args_w:
self.items_w.insert(j, e)
j += 1
return self

0 comments on commit dbce6f2

Please sign in to comment.
You can’t perform that action at this time.