From caf93a12841e8a001c338045c7e17ed0622ec8ce Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 24 Jul 2009 02:05:20 +0200 Subject: implement Array#wrap for n < 0 --- code/extensions/basic.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'code') diff --git a/code/extensions/basic.rb b/code/extensions/basic.rb index b04dc71d..5244a459 100644 --- a/code/extensions/basic.rb +++ b/code/extensions/basic.rb @@ -14,7 +14,11 @@ end class Array def wrap(n) # TODO: this can be done better... - n.times { push shift } + if n >= 0 + n.times { push shift } + else + n.abs.times { unshift pop } + end end def cdr(n = 1) self[n .. -1] -- cgit 1.4.1-2-gfad0