From: "Iñaki Baz Castillo" Date: 2011-08-15T01:32:41+09:00 Subject: Re: How to use "case" to match class names? (=== not so funny) 2011/8/14 Chris White : > One way to potentially get around this is to have an object that simple holds a class and overrides the === operator to make case work properly: > > class ClassCheck >  def initialize(klass) >    @holder = klass >  end > >  def ===(other) >    @holder == other >  end > end > > klass = String > > case klass >  when ClassCheck.new(String) >    puts "String" >  else >    puts "Nothing" > end > > You could also modify it to accept a variable number of arguments to check against multiple classes in a single when statement: > > class ClassCheck >  def initialize(*klass) >    @holder = klass >  end > >  def ===(other) >    @holder.each { | klass | >      return true if klass == other >    } >    false >  end > end > > klass = String > > case klass >  when ClassCheck.new(Object, Numeric, String) >    puts "One of these" >  else >    puts "Nothing" > end > > This form works with a single class as well. Really great, thanks a lot. -- Iñaki Baz Castillo