Project

General

Profile

Actions

Misc #16436

open

hash missing #last method, make it not so consistent (it has #first)

Added by zw963 (Wei Zheng) almost 5 years ago. Updated almost 4 years ago.

Status:
Open
Assignee:
-
[ruby-core:96339]

Description

(pry):main(0)> h = {x:1, y:2, z:3}
{
    :x => 1,
    :y => 2,
    :z => 3
}
(pry):main(0)> h.first
[
    :x,
    1
]
(pry):main(0)> h.first.first
:x
(pry):main(0)> h.first.last
1

last method not exist.

(pry):main(0)> h.last

Exception: NoMethodError: undefined method `last' for {:x=>1, :y=>2, :z=>3}:Hash

We have to use #to_a to make last working.

(pry):main(0)> h.to_a.last
[
    :z,
    3
]

(pry):main(0)> h.to_a.last.first
:z
(pry):main(0)> h.to_a.last.last
3
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0