diff --git a/fabfile/travis.py b/fabfile/travis.py index 2c6f8dc88..ac6256534 100644 --- a/fabfile/travis.py +++ b/fabfile/travis.py @@ -140,6 +140,7 @@ def run_specs(binary, prefix=""): "core/array/delete_at_spec.rb", "core/array/empty_spec.rb", "core/array/frozen_spec.rb", + "core/array/last_spec.rb", "core/array/length_spec.rb", "core/array/plus_spec.rb", "core/array/push_spec.rb", diff --git a/topaz/objects/arrayobject.py b/topaz/objects/arrayobject.py index 99a520fd6..0b200a009 100644 --- a/topaz/objects/arrayobject.py +++ b/topaz/objects/arrayobject.py @@ -2,6 +2,7 @@ from rpython.rlib.listsort import TimSort +from topaz.coerce import Coerce from topaz.module import ClassDef, check_frozen from topaz.modules.enumerable import Enumerable from topaz.objects.objectobject import W_Object @@ -333,7 +334,16 @@ def first """) @classdef.method("last") - def method_last(self, space): + def method_last(self, space, w_count=None): + if w_count is not None: + count = Coerce.int(space, w_count) + if count < 0: + raise space.error(space.w_ArgumentError, "negative array size") + start = len(self.items_w) - count + if start < 0: + start = 0 + return space.newarray(self.items_w[start:]) + if len(self.items_w) == 0: return space.w_nil else: