Hi --

On Thu, 10 Oct 2002, Bill Tj wrote:

> I am really curious whether the original poster got "overlapped
> arrays" problem , or "nbs.length == 0" problem, or both, when the code
> finished executing.  This is because although
>
>     nbs[12]
>
> may return a non-empty array,
>
>     nbs.each_key {|key| puts key}
>
> does not print anything, as nbs.length == 0.  Is this a commonly known
> Ruby hash feature?

Yes: the presence of a default value (even a non-nil one) is not the
same as the presence of a key/value pair.  So nbs is an empty hash
whose default value happens not to be nil.

(Consider the alternative.  If setting a default actually populated
the hash, what would hsh.keys consist of? :-)


David

-- 
David Alan Black                      | Register for RubyConf 2002!
home: dblack / candle.superlink.net     | November 1-3
work: blackdav / shu.edu                | Seattle, WA, USA
Web:  http://pirate.shu.edu/~blackdav | http://www.rubyconf.com