[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6642] Hash with a key of nil ?

From: rpmohn@... (Ross Mohn)
Date: 2000-11-29 17:10:01 UTC
List: ruby-talk #6642
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

In This Thread

Prev Next