From: furufuru@... (Ryo Furue) Date: 2001-12-01T00:16:56+09:00 Subject: [ruby-talk:27074] Re: String#== : Why not error with different type? Dave Thomas wrote in message news:... > furufuru@ccsr.u-tokyo.ac.jp (Ryo Furue) writes: > > > I've considered the problem hard and I think I understand. I think > > the earlier example Matz gave > > > > ary.select{|x| x == "foo"} > > > > is an answer. This does have a danger, which I described earlier. > > But, design 1 would complicate this much, as he said. And this > > (perhaps) outweighs the danger. So I'm (perhaps :) convinced. > > Think of this in human terms. If I point at a cow, and ask you "is > this a car?", do you do the Star Trek thing, screaming "this does not > compute, this does not compute" until your head explodes? Or do you > look at me calmly, say "no", and wonder if perhaps my medication is > wearing off. > > It's the same with Ruby. > > if a_cow == a_car > puts "act surprised" > end I'm not trying to contradict, but this type of rather abstract, philosophical explanation isn't convincing, I'm afraid. (No offense intended. I really apreciate your kindness.) Those people who already have enough experience and understanding will find such an explation enligtening, but those who don't won't. That is, experience can give philosophical summaries, but not the other way round. My reaction was: "Well, sounds correct. But, what does this have to do with real code?" I still wondered why a_cow == a_car returning false rather than raising an exception will help write good code. I wanted to know which design of #== is best in what context in real code. And, as I said, I think I understand at least this matter of the #== method. I hope time will come when I really understand your philosophical point. > Remember, in Ruby, classes aren't types, so it would be pretty hard to > implement equality which used type checks. I'll think about it. > > Finally, I'd like to find a way to avoid the danger. Could someone > > tell me what "the unit test" is? Is it RubyUnit? Where can I find a > > documentation? I searched the Ruby-talk archive, but there too many > > articles that mention RubyUnit... > > Unit testing is a philosophy of testing your code in small chunks,[...] Thank you for the explanation! Cheers, Ryo