The keys in the hash appear to be strings, so use: product[1]["id"]

Although what you wrote doesn't match the data structure, so I'm kind
of guessing here.

On 25 May 2012 17:11, Maksim D. <lists / ruby-forum.com> wrote:
> I have this array. I want to access the stuff in the hashes.
>
> i can loop through them all and get the individual hashes but i cannot
> access the data.
>
> products.each.do |product|
> =A0 =A0 product[1]
> =A0 =A0 #this gives me the hash
> =A0 =A0 #product[1].id and product[1][:id] does not work
> end
>
> How do i access the name and description and rateplans inside this
> structure.
>
> Thanks in advance!
>
> products =3D> ["prod0", {"id"=3D>"4028e6963457a2a001345934b93633e4",
> "name"=3D>"Product 1", "description"=3D>"This is a cool product with 4 ra=
te
> plans of different frequencies",
> "rate_plans"=3D>{"rp0"=3D>{"id"=3D>"4028e6963457a2a001345936b60d33fa",
> "name"=3D>"Quarterly Rate Plan", "description"=3D>"This is a Quarterly Ra=
te
> Plan billed every quarter.", "uom"=3D>"Seat",
> "charges"=3D>{"rpc0"=3D>{"id"=3D>"4028e697343fffc20134593a0a242ebd",
> "uom"=3D>"Seat", "quantity"=3D>"5", "name"=3D>"New Component", "price"=3D=
>0,
> "charge_model"=3D>"Per Unit Pricing"}}, "quantifiable"=3D>true},
> "rp1"=3D>{"id"=3D>"4028e697343fffc2013459355d232e61", "name"=3D>"Monthly =
Rate
> Plan", "description"=3D>"This is the Monthly Rate Plan which is the most
> basic plan", "uom"=3D>"Seat",
> "charges"=3D>{"rpc0"=3D>{"id"=3D>"4028e697343fffc20134593678b12e65",
> "uom"=3D>"Seat", "quantity"=3D>"5", "name"=3D>"New Component", "price"=3D=
>0,
> "charge_model"=3D>"Per Unit Pricing"}}, "quantifiable"=3D>true},
> "rp2"=3D>{"id"=3D>"4028e697343fffc20134593a4b652ec4", "name"=3D>"Semi-Ann=
ual
> Rate Plan", "description"=3D>"This is a Semi-Annual Rate Plan billed ever=
y
> 6 months.", "uom"=3D>"Seat",
> "charges"=3D>{"rpc0"=3D>{"id"=3D>"4028e6963457a2a00134593ac09f3415",
> "uom"=3D>"Seat", "quantity"=3D>"5", "name"=3D>"New Component", "price"=3D=
>0,
> "charge_model"=3D>"Per Unit Pricing"}}, "quantifiable"=3D>true},
> "rp3"=3D>{"id"=3D>"4028e697343fffc20134593b63272ecd", "name"=3D>"Annual R=
ate
> Plan", "description"=3D>"This is an Annual Rate Plan billed yearly",
> "uom"=3D>"Each",
> "charges"=3D>{"rpc0"=3D>{"id"=3D>"4028e6963457a2a00134593ba494343a",
> "uom"=3D>"Each", "quantity"=3D>"5", "name"=3D>"New Component", "price"=3D=
>0,
> "charge_model"=3D>"Per Unit Pricing"}}, "quantifiable"=3D>true}}}]
>
> --
> Posted via http://www.ruby-forum.com/.
>



--=20
=A0 Matthew Kerwin, B.Sc (CompSci) (Hons)
=A0 http://matthew.kerwin.net.au/
=A0 ABN: 59-013-727-651

=A0 "You'll never find a programming language that frees
=A0 you from the burden of clarifying your ideas." - xkcd