From: dblack@... Date: 2007-09-05T19:51:56+09:00 Subject: Re: assigning to hash keys when there is a default value? --1926193751-1451961309-1188989512=:1699 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1451961309-1188989512=:1699" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-1451961309-1188989512=:1699 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Wed, 5 Sep 2007, Pe=F1a, Botp wrote: > From: Robert Klemme [mailto:shortcutter@googlemail.com] > # 2007/9/4, Yossef Mendelssohn : > # > If '"x+=3D1" will always be "x=3Dx+1"', what's the problem in > # having x ||=3D > # > 1 always be x =3D x || 1? > # That an assignment of x=3Dx is useless (basically a nop in the standard > # case of x being a variable). > > consider, > > irb(main):074:0* h=3DHash.new > =3D> {} > irb(main):075:0> h[5] =3D h[5] > =3D> nil > irb(main):076:0> h > =3D> {5=3D>nil} > irb(main):062:0* h=3DHash.new(1) > =3D> {} > irb(main):063:0> h[5] =3D h[5] > =3D> 1 > irb(main):064:0> h > =3D> {5=3D>1} > > thus h[k] =3D h[k] could mean > h[k] =3D h.default or > h[k] =3D nil > > definitely not useless and not noop. It's really always h[k] =3D h.default -- it's just that the default default, so to speak, is nil. David --=20 * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) --1926193751-1451961309-1188989512=:1699-- --1926193751-1451961309-1188989512=:1699--