From: "Gavin Sinclair" <gsinclair / soyabean.com.au>
Subject: Re: Transforming...
Date: Mon, 5 Jul 2004 16:07:19 +0900

Hi Gavin,

 whow! what a fast reply ! Thank you very much ! :)

 I want an algorithm, which when applied like this

   b=<algo>

 it does the same as I would do this by hand:

   b=[[<val1>,<val2>,<val3>],[<val4>,<val5>,<val6>],[<val7>,<val8>,<val9>]]

 

> Meino wrote:
> 
> >  In my program there is a hash of this form
> >
> > 	   a={ "<string_a>" => [<val1>,<val2>,<val3>],
> > 		   "<string_b>" => [<val4>,<val5>,<val6>],
> > 		   "<string_c>" => [<val7>,<val8>,<val9>]
> > 		   }
> >
> >   I am looking for a short and handy way to produce an array out of
> > this, which looks like:
> >
> > 	 b=[[<val1>,<val2>,<val3>],[<val4>,<val5>,<val6>],[<val7>,<val8>,<val9>]]
> >
> >  without iterating over the hash.
> 
> I presume you mean you just want an array of the *values* in the hash?
> 
>   b = a.values
> 
> If you want the values sorted according to the order of the keys:
> 
>   b = a.keys.sort.map { |k| a[k] }
> 
> Cheers,
> Gavin
> 
> 
> 
> 
>