From: Rick DeNatale Date: 2007-11-02T01:17:39+09:00 Subject: Re: use of case statement doesn't work as I expect :( help appreciated! On 11/1/07, Gabriel Dragffy wrote: > Hi all, > > I have an object ( a website tester) that can return various values. > One of which is Net:HTTPOK, I want to use a case statement to evaluate > this and set a variable called 'severity', as follows: > > result = TestWebsite::test( site ) > case result > when Net::HTTPOK > severity = :INFO > when SocketError > severity = :ERROR > else > severity = :WARN > end This form of case case x when y ... is logically equivalent to: if y === x ... Now Net::HTTPOK is a class, and class implements === as a test of whether the argument is an instance of the class or a subclass. Array === [] #=> true Array === Array #=> false If response is really the class then you either want to use if/elsif or case when result == Net::HTTPOK ... -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/