> However, I was surprised to find out that the construction
> 
> lots = Hash.new
> lots['ALA'] = 2
> lots['IBM'] = 4
> 
> lots.keys do |k|
>   puts k
> end
> 
> does not print out anything, nor does it flag a syntax violation.  This
> was a "Maximum Surprise".

you violate nothing, but lots.keys simply does not use the block you
pass to it. It returns an array with all keys in it, though!

Now:

  lots = Hash.new do |k|
    puts k
  end

is perfectly legal and does not print anything, either. It still
returns an empty Hash.

Because a block is kind of an ``extra'' parameter, it is not detected
when it is not used. The other way around is detected:

  lots.each_key()

will produce an error (yield called out of block, i.e, "yield" tried
to execute a block, but found none).

Remember by: an iterator usually contains the word "each" somewhere.

Bye,
Kero.

+--- Kero ------------------------------ kero / chello.nl ---+
|  Don't split your mentality without thinking twice       |
|                          Proud like a God -- Guano Apes  |
+--- M38c ------- http://members.chello.nl/~k.vangelder ---+