[ruby-it] Perché Hash#partition non restituisce due Hash?

Alessandro Scolavino scolas a gmail.com
Gio 3 Dic 2009 13:29:29 CET


Guido De Rosa wrote:

> 
> So che è facilissimo convertire gli Array di sopra negli Hash di sotto,
> ma mi chiedo il motivo di tale inconsistenza in core ruby. Cosa mi
> sfugge?
> 

Non è un inconsistenza, è voluto:
dalle api:

enum.partition {| obj | block } => [ true_array, false_array ]

Returns two arrays, the first containing the elements of enum for which 
the block evaluates to true, the second containing the rest.

   (1..6).partition {|i| (i&1).zero?}   #=> [[2, 4, 6], [1, 3, 5]]

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


More information about the Ml mailing list