--------------enig76C2E74EC4D20351F9B9017D
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Ken Bloom wrote:
> Try this-- it's more concise, and you probably won't feel the need
> for more syntactic magic after that.
> 
> def test(args)
>   args[:a] ||= 'defaultA'
>   args[:b] ||= 'defaultB'
>   args[:c] ||= 'defaultC'
>   puts args.indexes(:a, :b, :c)
> end
> 

I find:

def test(args)
  realargs = {:a => 'defaultA',
   :b => 'defaultB',
   :c => 'defaultC'}.update(args)

  puts args.indexes(:a, :b, :c)
end

more readable. Preferrably extracting the default values into constants
before the method definition and (deep?)cloning the hash.

Also, your code clobbers the hash put into args by putting in values.
This might not cause bugs most of the case, but might in case someone
passes in an actual hash, so I'd just stay on the safe side.

David Vallner


--------------enig76C2E74EC4D20351F9B9017D
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFeSCcy6MhrS8astoRAlSWAJ4j1bfWNoqvQyn9dNfjz0PRsvpITwCdHtak
hYW7ABELXOYbcHNR/CgJa2I
MD -----END PGP SIGNATURE----- --------------enig76C2E74EC4D20351F9B9017D--