From: Dave Thomas Date: 2003-04-18T02:01:32+09:00 Subject: Re: case statements and classes On Thursday, April 17, 2003, at 11:55 AM, Chris Pine wrote: > In general, I love the way case statement matching works. I'm having > trouble, however, when trying this: > > irb(main):001:0> case Integer > irb(main):002:1> when String then 'str' > irb(main):003:1> when Integer then 'int' > irb(main):004:1> when Array then 'arr' > irb(main):005:1> else '???' > irb(main):006:1> end > => "???" > It's because the more common use is to compare objects with their classes: case 1 when Integer then 'int' ... end > Any ideas, other than `if ... elsif ... elsif .. else'? Is there any > way to > make case use == instead of ===? Or something? > How about using a Hash: ClassNames = { Integer => 'int', Strin => 'str' } ClassNames.default = '???' Classnames[Integer] #-> int Cheers Dave