From: Alva Date: 2001-09-17T18:07:12+09:00 Subject: [ruby-talk:21279] Re: Exceptions and Ruby On Sun, 16 Sep 2001 17:40:44 +0200, you wrote: >[Alva] >> Why accessing out-of-range index in Array or not existing >> key in Hash doesn't yield exception? This is definately >> programming error, so shouldn't the interpretar aid me >> in finding it? Now you probably get something like NameError >> sooner or later, when you'll try to invoke method on nil, but this >> isn't half that descriptive as say IndexError. > >It is more convenient, allowing you to write, for example, > > hash[x] ||= 1 > >instead of > > hash[x] = 1 if not hash.has_key?(x) > Ugh, you got me. What does the operator ||= do? Couldn't find it in manual. >If you prefer "safer" programming you can always use fetch or change the >implementation of [] > > class Hash > def [](x) > fetch(x) > end > end > Great, thanks Pozdrawiam, Tomek 'Alva' Wr�blewski -- r e k l a m a Lista P�ac [ http://listaplac.onet.pl ]