From: "Jesús Burgos Maciá" Date: 2016-03-11T09:53:55+01:00 Subject: [ruby-core:74275] Re: [Ruby trunk Feature#12165] Hash#first, Hash#last --===============0392371445== Content-Type: multipart/alternative; boundary=001a11418d1e318b0a052dc212e7 --001a11418d1e318b0a052dc212e7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable There's documentation for `#first`, you need to look for it in `Enumerable`, rather than `Hash`: http://docs.ruby-lang.org/en/2.3.0/Enumerable.html#method-i-first Enumerable lacks a `#last` method. I presume the main reason for that is because an enumerable object may not have a last element. On 10 March 2016 at 19:00, wrote: > Issue #12165 has been reported by Fabian Stillhart. > > ---------------------------------------- > Feature #12165: Hash#first, Hash#last > https://bugs.ruby-lang.org/issues/12165 > > * Author: Fabian Stillhart > * Status: Open > * Priority: Normal > * Assignee: > ---------------------------------------- > 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=3D>true, :b=3D>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 > =3D> [:a, true] > ~~~ > > I would assume the Hash#last method would work like the Hash#first method= : > > ~~~ruby > {a: true, b: false}.last > =3D> [: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/ > > Unsubscribe: > > --=20 Jes=C3=BAs Burgos Maci=C3=A1 --001a11418d1e318b0a052dc212e7 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
There's documentation for `#first`, you need to look f= or it in `Enumerable`, rather than `Hash`: http://docs= .ruby-lang.org/en/2.3.0/Enumerable.html#method-i-first

Enumerable lacks a `#last` method. I presume the main reason for that is= because an enumerable object may not have a last element.

On 10 March 2016 at 19= :00, <fabian_stillhart@hotmail.com> wrote:
Issue #12165 has been reported by Fabian Still= hart.

----------------------------------------
Feature #12165:=C2=A0 Hash#first, Hash#last
https://bugs.ruby-lang.org/issues/12165

* Author: Fabian Stillhart
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
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=3D>true, :b=3D>= ;false}:Hash
~~~

Interestingly I while playing arround I found out that the Hash#first metho= d works. But why is it not in the ruby-doc?

~~~ruby
{a: true, b: false}.first
=3D> [:a, true]
~~~

I would assume the Hash#last method would work like the Hash#first method:<= br>
~~~ruby
{a: true, b: false}.last
=3D> [: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/

Unsubscribe: <mailto:= ruby-core-request@ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/m= ailman/options/ruby-core>



--
Jes=C3=BAs Burgos Maci=C3=A1
--001a11418d1e318b0a052dc212e7-- --===============0392371445== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: --===============0392371445==--