Assignment 9 FAQs, Corrections, and more

A label.rb PITFALL with Hash subscripting

Here's something I expect to work:

for key in hash do
    value = hash[key]
    ...work with key and value...
end

HOWEVER, in some cases with keys that are arrays or hashes, value will be nil!

This problem can be avoided by iterating through the key/value pairs in tandem, like this,

for key,value in hash do
    ...work with key and value...
end
or this:
hash.each do
    |key,value|
    ...work with key and value...
end

This problem can also be avoided by calling .compare_by_identity on a Hash, like this:

h = {}.compare_by_identity
but I'm resistant to doing that in the tests for label.rb.

FAQs

None yet.

Corrections (web copy has been updated)

  1. The Turning in your work specified a8 instead of a9, and had a redundant paragraph, too.