えぐち@エスアンドイー です。

>>> On Fri, 30 Oct 1998 02:55:52 +0900, MineroAoki <aamine / dp.u-netsurf.ne.jp> said:

aamine> あおきです。
aamine> 
aamine> 今日発見したのですが、
aamine> 
aamine> case 'This is string'.type
aamine> when Array   then p "array\n"
aamine> when Integer then p "integer\n"
aamine> when String  then p "string\n"
aamine> else              p "Don't match\n"
aamine> end
aamine> 
aamine> はelseにヒットするんですね。これはそういうものなんでしょうか?
aamine> 単純に考えると、Stringにヒットしそうなものですが、なにか特別な
aamine> 理由があるのでしょうか。

    % cat type.rb
    case 'This is string'.type
    when Array.type   then p "array\n"
    when Integer.type then p "integer\n"
    when String.type  then p "string\n"
    else                   p "Don't match\n"
    end

    % ruby type.rb
    "array\n"

ということです。
たしかに、

    % ruby -e "p 'This is string'.type"
    String

で、

    % ruby -e "p ('This is string'.type == String)"
    true

ですが、

    % ruby -e "p ('This is string'.type === String)"
    false

です、また

    % ruby -e "p 'This is string'.type.type"
    Class

となります。
when では、 eqq (===) な比較が行なわれるので、
..と言う事で、Class クラス同士に eqq ( === ) を作用っさせた時
の挙動からこのようになります。

	えぐち