From: Robert Klemme Date: 2009-04-08T01:04:09+09:00 Subject: Re: barenames and case statements On 07.04.2009 17:21, LAMBEAU Bernard wrote: > Because the === operator of the Class class (used in case statements) > checks for 'is an instance of'. > > So, the following: > >> case klass >> when String >> puts "String!" >> end > > is to be interpreted as String===klass, that is to, > klass.is_a?(String), which is false. But the following is true: > > case klass > when Class > puts 'It's a class of course' > end A solution would be to use the other form of "case": [String, Array, Hash].each do |klass| case when klass == String puts "String!" when klass == Array puts "Array!" when klass == Hash puts "Hash!" else puts "I don't know: #{klass}" end end Or encapsulate tests in a special instance: IsString = Object.new def IsString.===(c) String == c end klass = String case klass when IsString puts "Ah!" end Kind regards robert