Array#shift(n)?

Pretty obvious question, really.

···


Gavin Sinclair Software Engineer
Sydney, Australia Soyabean Software Pty Ltd

Yeah, very obvious …

···

Gavin Sinclair gsinclair@soyabean.com.au wrote:

Pretty obvious question, really.

Pretty obvious question, really.

Hmmm… no-one’s taken the ball…

I have two or three times now wished that Array#shift(n) was implemented.

(quickly checks that it’s not…)

As in:

x = [1,2,3,4,5]
x.shift # => 1
x.shift(2) # => [2, 3]

I can (now) sort of see why that might be a bit irksome - returning different
types - but in practice:

foo, bar = ARGV.shift(2)
baz = ARGV.shift

That would work under the specification-by-example above. I know I can use
#slice!, but #shift just seems so right.

Gavin

···

From: “Gavin Sinclair” gsinclair@soyabean.com.au