From: Gavin Sinclair Date: 2003-08-12T13:49:27+09:00 Subject: Re: using case with classes >> def test( obj ) >> case obj >> when Array then puts "Array" >> when Hash then puts "Hash" >> when Class then puts "Class" >> else puts "ugh" >> end >> end > > How about > > def test(obj) > if [Array, Hash, Class].include?(obj.class) then > puts obj.class.to_s > else > puts "ugh" > end > end > > I suspect that the case statement may be faster. > How about def test(obj) puts \ case obj when Array, Hash, Class then obj.class else; "ugh" end end ? Gavin