* [ruby-core:101949] [Ruby master Misc#16436] hash missing #last method, make it not so consistent (it has #first)
[not found] <redmine.issue-16436.20191219162135.2083@ruby-lang.org>
@ 2021-01-06 9:47 ` fabian.stillhart1
0 siblings, 0 replies; only message in thread
From: fabian.stillhart1 @ 2021-01-06 9:47 UTC (permalink / raw)
To: ruby-core
Issue #16436 has been updated by fun_with_eval (Fabian Stillhart).
This seems to be a duplicate of my old feature request: https://bugs.ruby-lang.org/issues/12165
----------------------------------------
Misc #16436: hash missing #last method, make it not so consistent (it has #first)
https://bugs.ruby-lang.org/issues/16436#change-89799
* Author: zw963 (Wei Zheng)
* Status: Open
* Priority: Normal
----------------------------------------
``` ruby
(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.
```ruby
(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.
```ruby
(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
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-06 9:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <redmine.issue-16436.20191219162135.2083@ruby-lang.org>
2021-01-06 9:47 ` [ruby-core:101949] [Ruby master Misc#16436] hash missing #last method, make it not so consistent (it has #first) fabian.stillhart1
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).