From: pe medeiros Date: 2012-12-11T06:50:33+09:00 Subject: Re: Dynamically create an array --20cf3074d862dd06d804d0868d45 Content-Type: text/plain; charset=ISO-8859-1 This code is not a valid hash in ruby 1.9.3. However if I unterstood what you are trying to ask, I would take a look at collect method for your array. in which may return an array of the return of a given block. e.g. grade = {"subject"=>:math, "Jim"=>94, "Billy"=>50} grade.collect { |key, value| value } # [:math 94, 50] grade.collect { |key, value| value unless key == 'subject' } # [nil, 94, 50] later you can use reject method of Array to remove the nil values. 2012/12/10 robert lengu > Hi Experts, > > I am trying to create an array from hash > > example in my hash I have value like > > > grades = > { { "subject" => english, > "Jim" => 94, > "Billy" => 58 > } > > { "subject" => math, > "Jim" => 90, > "Billy" => 80 > } > > { "subject" => science, > "Jim" => 99, > "Billy" => 58 > } > > } > > now i want to make an array or output like this > > 94,90,99 > 58,80,58 > > > i am looking for some help in google but no luck > > Robert > > -- > Posted via http://www.ruby-forum.com/. > > -- Pedro Henrique de Souza Medeiros ---------------------------------- Cel: +55 (61) 9197-0993 Email: pedrosnk@gmail.com Beautiful is better than ugly, Explicit is better than implicit, Simple is better than complex, Complex is better than complicated. The Zen of Python, by Tim Peters --20cf3074d862dd06d804d0868d45 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable This code is not a valid hash in ruby 1.9.3.
However if I unterstood wh= at you are trying to ask, I would take a look at collect method for your ar= ray.

in which may return an array of the return of= a given block.

e.g.

grade =3D=A0{"subjec= t"=3D>:math, "Jim"=3D>94, "Billy"=3D>50}<= /div>
grade.collect { |key, value| value =A0} # [:math 94, 50]
grade.collect { |key, value| value unless key =3D=3D 'subject'= ; =A0} # [nil, 94, 50]

later you can use reject method of Array to remov= e the nil values.


2012/12/10 robert lengu <lists@ruby-forum.com><= br>
Hi Experts,

I am trying to create an array from hash

example in my hash I have value like


grades =3D
{ { "subject" =3D> english,
=A0 =A0 =A0 =A0 =A0 =A0"Jim" =3D> 94,
=A0 =A0 =A0 =A0 =A0 =A0"Billy" =3D> 58
=A0 =A0 =A0 =A0 =A0}

=A0 =A0{ "subject" =3D> math,
=A0 =A0 =A0 =A0 =A0 =A0"Jim" =3D> 90,
=A0 =A0 =A0 =A0 =A0 =A0"Billy" =3D> 80
=A0 =A0 =A0 =A0 =A0}

=A0 =A0 { =A0"subject" =3D> science,
=A0 =A0 =A0 =A0 =A0 =A0"Jim" =3D> 99,
=A0 =A0 =A0 =A0 =A0 =A0"Billy" =3D> 58
=A0 =A0 =A0 =A0 =A0}

}

now i want to make an array or output like this

94,90,99
58,80,58


i am looking for some help in google but no luck

Robert

--
Posted via http://= www.ruby-forum.com/.




-- Pedro Henrique de Souza Medeiros
----------------------------------Cel: +55 (61) 9197-0993
Email: pedrosnk@gmail.com

Beautiful is better than ugly,
Explicit is better than implicit,
Simple is better than complex,
Complex is better than complicated.

T= he Zen of Python, by Tim Peters


--20cf3074d862dd06d804d0868d45--