From: Harry Kakueki Date: 2013-03-29T18:32:06+09:00 Subject: Hash with default --047d7b86f418298d0804d90cdd7e Content-Type: text/plain; charset=ISO-8859-1 I would like to make a hash like h2 with the default described by h in one line when I create the hash instead of 3 lines and 2 hashes like I did here. Any ideas? h = Hash.new {|x,y| x[y] = y} h2 = {"two"=>2,"three"=>3} h.merge!(h2) p h["two"] #> 2 p h["tree"] #> "tree" Harry --047d7b86f418298d0804d90cdd7e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I would like to make a hash like h2 with the default = described by h in one line when I create the hash instead of 3 lines and 2 = hashes like I did here.
Any ideas?

h =3D Hash.new {|x,y| x[y] =3D= y}
h2 =3D {"two"=3D>2,"three"=3D>3}
h.merge!(h2)<= br>p h["two"]=A0=A0=A0=A0 #> 2
p h["tree"]=A0=A0= =A0 #> "tree"



Harry

--047d7b86f418298d0804d90cdd7e--