From: Robert Klemme Date: 2013-06-29T04:26:40+09:00 Subject: Re: Find elment in array of hashes --089e0149cab09ef0c504e03bdbdf Content-Type: text/plain; charset=ISO-8859-1 On Fri, Jun 28, 2013 at 7:21 PM, Rodrigo Lueneberg wrote: > array = {:id=>1, :price =>0.25} # index[0] > {:id=>2, :price =>0.35} # index[1] > {:id=>3, :price =>0.25} # index[2] > > I am beginning to adventure in Ruby and I need to find in this array of > hashes the id with the value of 3 and get its price. What would be the > easiest way to do it? > There is no Array: ruby <1, :price =>0.25} # index[0] {:id=>2, :price =>0.35} # index[1] {:id=>3, :price =>0.25} # index[2] p array XXXX {:id=>1, :price=>0.25} Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --089e0149cab09ef0c504e03bdbdf Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Fri, Jun 28, 2013 at 7:21 PM, Rodrigo Lueneberg <lists@ruby-= forum.com> wrote:
array =3D {:id=3D>1, :price =3D>0.25} # index[0]
=A0 {:id=3D>2, :price =3D>0.35} # index[1]
=A0 {:id=3D>3, :price =3D>0.25} # index[2]

I am beginning to adventure in Ruby and I need to find in this array of
hashes the id with the value of 3 and get its price. What would be the
easiest way to do it?=A0
<= br>
There is no Array:

ruby <<XXXX
array =3D {:id=3D>1, :price =3D>0.25} # index[0]
=A0 {:id=3D>2, :price =3D>0.35} # index[1]
=A0 {:id=3D>3, :price =3D>0.25} # index[2]

p array
XXXX
{:id=3D>1, :price=3D>0.25}

Cheers

robert

=
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
--089e0149cab09ef0c504e03bdbdf--