Forum: Ruby about Array methods

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kyung won C. (Guest)
on 2009-01-09 04:49
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?
Matthew M. (Guest)
on 2009-01-09 05:00
(Received via mailing list)
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]
Peña, Botp (Guest)
on 2009-01-09 05:16
(Received via mailing list)
From: Matthew M. [mailto:removed_email_address@domain.invalid]
# > p l    # => [1,2,3,4,5]
# >
# > # I want '[4,5]'
# >
# > # Is that method in Array?
#
# l = l[3..-1]
#

also,

  array.last(2)
Mathijs (Guest)
on 2009-01-09 11:10
(Received via mailing list)
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 topic is locked and can not be replied to.