From: Peter Hickman Date: 2013-07-19T23:49:33+09:00 Subject: Re: need to help to get data from bellow syntax --001a11c3fb102d7cd104e1de6f0a Content-Type: text/plain; charset=ISO-8859-1 The [ and ] indicate a list. So we need to loop over the list bellow_syntax = [{:name=>"value1"}, {:name=>"Value2"}] bellow_syntax.each do |item| p item end This prints out the items in the list as shown bellow {:name=>"value1"} {:name=>"Value2"} The { and } indicate a hash. We want the value of the :name key so we do this: bellow_syntax.each do |item| p item[:name] end and this prints out "value1" "Value2" In a more Rubyish way we can do this p bellow_syntax.map{|x| x[:name]} which returns a list of the values ["value1", "Value2"] If you don't know what list and hashes are, and the fact that you asked this question means that you don't, please follow the various tutorials that get mentioned in this list on an almost daily basis. Once you have done that the final answer I gave you will make sense. --001a11c3fb102d7cd104e1de6f0a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
The [ and ] indicate a list. So we need to loop over the l= ist

bellow_syntax =3D [{:name=3D>"valu= e1"}, {:name=3D>"Value2"}]

bello= w_syntax.each do |item|
=A0 p item
end

This pri= nts out the items in the list as shown bellow

{:name=3D>"value1"}
{:name=3D>"Value2"= }

The { and } indicate a hash. We want the value of= the :name key so we do this:

bellow_syntax.e= ach do |item|
=A0 p item[:name]
end
and this prints out

"value1&q= uot;
"Value2"

In a more = Rubyish way we can do this

p bellow_syntax.map{|x|= x[:name]}

which returns a list of the values

=
["value1", "Value2"]

If y= ou don't know what list and hashes are, and the fact that you asked thi= s question means that you don't, please follow the various tutorials th= at get mentioned in this list on an almost daily basis. Once you have done = that the final answer I gave you will make sense.


--001a11c3fb102d7cd104e1de6f0a--