From: rpmohn@... (Ross Mohn) Date: 2000-11-30T02:10:01+09:00 Subject: [ruby-talk:6642] Hash with a key of nil ? While reading data in from a file and populating a hash, I accidentally added a key/val pair of nil/nil. All was fine until I tried to sort the hash and got "NameError: undefined method `<=>' for nil". I know I should check for nils before populating a hash, but it raises two questions in my mind: 1) Should nil be allowed as a Hash key? This does not make sense to me. 2) Maybe there should be a method defined for nil.<=> ? I think if it always returned -1 it would be appropriate. -RPM x={"a"=>1, nil=>nil} --> {nil=>nil, "a"=>1} x --> {nil=>nil, "a"=>1} x.keys --> [nil, "a"] x.values --> [nil, 1] x.sort --> NameError: undefined method `<=>' for nil --> `<=>' --> `sort' --> in `irb_binding' -- Ross Mohn rpmohn@panix.com