From: Fearless Fool Date: 2010-09-09T06:25:59+09:00 Subject: Re: Problem with Hash of Arrays @Gary, @Chris: You're both right, of course: a *real* programmer will *always* use has_key?() (or equivalent) to check for a non-empty slot in a hash table! Or will she? Consider the following example: 1: sentence = ParserModule.parse(string) 2: if (p = sentence[:preposition]) 3: ... Depending on how the 'sentence' hash table is constructed, line 2 may or may not modify the state of the hash table, and YOU CANNOT KNOW unless you look inside the ParserModule. Why is it bad if the state of the hash table changes unexpectedly? I dunno: maybe your code depends on the number of elements in the hash, or (as the code above suggests) the distinction between a nil slot and a non-nil slot is important. But for line 2 to modify the state of the hash table is a clear violation of "The Principle of (Matz's) Least Surprise". - ff P.S.: If you claim that it's better to write this as: 1: sentence = ParserModule.parse(string) 2. if sentence.has_key?(:preposition) 3. p = sentence[:preposition] ... ... I'll sic the DRY police on you. :) -- Posted via http://www.ruby-forum.com/.