uno può dire perché il seguente:Rubino iniettare con iniziale essendo un hash
['a', 'b'].inject({}) {|m,e| m[e] = e }
genera l'errore:
IndexError: string not matched
from (irb):11:in `[]='
from (irb):11:in `block in irb_binding'
from (irb):11:in `each'
from (irb):11:in `inject'
from (irb):11
from C:/Ruby192/bin/irb:12:in `<main>'
, mentre le seguenti opere?
a = {}
a["str"] = "str"
È assolutamente necessario includere la m alla fine? Ad esempio, se il blocco era '{| array, (k, v) | array << MyObject.new (k, v)} 'funzionerebbe? Considerando che 'array. <<' restituisce l'array. – Ziggy
@Ziggy: sì, è necessario perché l'assegnazione 'hash [chiave] = valore' restituisce' valore', e hai bisogno di 'hash'. – tokland