Voglio creare un hash in Ruby con valori di default come un array vuotoCreazione di un hash con i valori come array e il valore predefinito come matrice vuota
Così, ho codificato
x = Hash.new([])
Tuttavia, quando ho cercare di spingere un valore in esso
x[0].push(99)
Tutti i tasti ottenere 99
spinto in tale matrice. Come posso risolvere questo?
'Hash.new {[]}' è quello che vuoi. –
@CarySwoveland questo restituirà un nuovo array senza memorizzarlo nell'hash – Stefan
@Stefan sul tuo telefono – Ninjinx