About Array methods

l = [1,2,3,4,5]
head = l[0…2]
p head # => [1,2,3]
p l # => [1,2,3,4,5]

I want ‘[4,5]’

Is that method in Array?

On Jan 8, 2009, at 8:49 PM, Kyung won Cheon wrote:

l = [1,2,3,4,5]
head = l[0…2]
p head # => [1,2,3]
p l # => [1,2,3,4,5]

I want ‘[4,5]’

Is that method in Array?

l = l[3…-1]

From: Matthew M. [mailto:[email protected]]

> p l # => [1,2,3,4,5]

>

> # I want ‘[4,5]’

>

> # Is that method in Array?

l = l[3…-1]

also,

array.last(2)

Kyung won Cheon schreef:

l = [1,2,3,4,5]
head = l[0…2]
p head # => [1,2,3]
p l # => [1,2,3,4,5]

I want ‘[4,5]’

Is that method in Array?

p l-head # => [4,5]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs