From: Harry Kakueki Date: 2013-03-29T18:59:54+09:00 Subject: Re: Hash with default --047d7b15a60d30941a04d90d55c5 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Mar 29, 2013 at 6:46 PM, Joel Pearson wrote: > If you want to do it in one line you could create a method which does > this, with whatever arguments you want to include. > > > Thanks. I was just wondering if there was a way to create the hash and set defaults at the same time. h = Hash.new({"two"=>2,"three"=>3}){|x,y| y} This does not work, but I want something like it. I can make it myself if necessary, I just didn't like the way it looked. It seemed wasteful to use 2 hashes. Harry --047d7b15a60d30941a04d90d55c5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On F= ri, Mar 29, 2013 at 6:46 PM, Joel Pearson <lists@ruby-forum.com>= wrote:
If you want to do it in o= ne line you could create a method which does
this, with whatever arguments you want to include.

=A0
<= br>
Thanks. I was just wondering if there was a way to create the= hash and set defaults at the same time.

h =3D Hash.new({"= ;two"=3D>2,"three"=3D>3}){|x,y|=A0 y}

This does not work, but I want somethi= ng like it.
I can make it myself if nec= essary, I just didn't like the way it looked.
It seemed wasteful to use 2 hashes.

Harry


--047d7b15a60d30941a04d90d55c5--