From: kjana@... (YANAGAWA Kazuhisa) Date: 2000-09-28T21:13:52+09:00 Subject: [ruby-talk:5172] Re: Types and === In message <004e01c028ee$da999680$01f9fea9@austin.rr.com> hal9000@hypermetrics.com writes: > 1. Why do we say "case other; when receiver" and not > "case receiver; when other"? Because we want to test some variable is in some container, in range, mathes some pattern and so on.... So the variable to be tested is naturally placed at the `position at which parameter occur'. For example: def daysuffix(day) case day when 4..20, 24..30 "th" when 1, 21, 31 "st" when 2, 22 "nd" when 3, 23 "rd" end end `day' is variable. Of course this code expect 1 <= day <= 31. Here we want to test where `day' fits. # Of course, more effective and natural code is available :-P > 2. Why is the argument order for pattern === string opposite > from the order for string =~ pattern? # There is Regexp#=~ so you can write patter =~ string. Standing on the basis above, `===' --- is NOT an equality operator --- in `when' clauses should test what the variable is for objects on a clause. Therefore Regexp#=== is defined as Regexp#=~, Range#=== as Range#include?, Class#=== tests the argument's class is subclass of self, etc. etc.... > It almost (I'm not serious here, not entirely) makes me want to propose > two more operators ==> and <== which point to the receiver... then > the === could be used for symmetrical cases. Operator `===' is not commutative from its standing basis. It IS an merely symbol which points methods called on when clauses. -- kjana@os.xaxon.ne.jp September 28, 2000 It is comparison that makes men happy or miserable.