From: Igor Sutton Lopes Date: 2007-06-29T09:43:35+09:00 Subject: Re: newby non/programmer trying to understand classes --Apple-Mail-14-759640886 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jun 28, 2007, at 9:16 PM, Rob Biedenharn wrote: > > Basically. If you just had: > > names = Hash.new > > then referencing non-existent keys gives nil, but they still do not > exist. > > names['joe'] << 'hello' > > would give an error trying to call nil.<<('hello') > > By assigning to h[k], that key is created in the 'names' hash with > the indicated value (an empty Array in this case). > > It's about the same as: > > names = Hash.new # or just names = {} > (names['joe'] ||= []) << 'hello' > Thanks for your explanation! --Apple-Mail-14-759640886 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin) iD8DBQFGhFWdKuhQxiIVvZwRAvP+AKDBwzBaL1INpOBHNzNWo5XBes8rrgCfQ/cG UKZG3GcdV+jOqwVMlKgA9zo= =GeBU -----END PGP SIGNATURE----- --Apple-Mail-14-759640886--