[#113435] [Ruby master Feature#19634] Pattern matching dynamic key — "baweaver (Brandon Weaver) via ruby-core" <ruby-core@...>
Issue #19634 has been reported by baweaver (Brandon Weaver).
6 messages
2023/05/09
[#113489] [Ruby master Bug#19642] Remove vectored read/write from `io.c`. — "ioquatix (Samuel Williams) via ruby-core" <ruby-core@...>
Issue #19642 has been reported by ioquatix (Samuel Williams).
10 messages
2023/05/15
[ruby-core:113500] [Ruby master Feature#12165] Hash#first, Hash#last
From:
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
Date:
2023-05-17 01:37:40 UTC
List:
ruby-core #113500
Issue #12165 has been updated by nobu (Nobuyoshi Nakada).
Although I've not thought about `Hash#last`, once when `st_table` got keeping the insertion order I proposed `Hash#reverse_each` (`st_reverse_foreach` for it precisely) to matz, but was rejected.
----------------------------------------
Feature #12165: Hash#first, Hash#last
https://bugs.ruby-lang.org/issues/12165#change-103095
* Author: stillhart (Fabian Stillhart)
* Status: Open
* Priority: Normal
----------------------------------------
Just run into a simple problem with a colleague and was wondering why there is no Hash#last method?
~~~ruby
{a: true, b: false}.last
NoMethodError: undefined method 'last' for {:a=>true, :b=>false}:Hash
~~~
Interestingly I while playing arround I found out that the Hash#first method works. But why is it not in the ruby-doc?
~~~ruby
{a: true, b: false}.first
=> [:a, true]
~~~
I would assume the Hash#last method would work like the Hash#first method:
~~~ruby
{a: true, b: false}.last
=> [:b, false]
~~~
If I am not wrong the order of a Hash is always the same when calling Hash#each. So wouldn't it make sense to have Hash#last method?
I tested it in Ruby 2.2.4 and Ruby 2.3.0.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/