"Iaki Baz Castillo" <ibc / aliax.net> wrote in post #1016614:
> But in my case, klass variable holds a class rather than a class
> instance. How could I use it within the above "case" statement? The
> only way I've found is:
>
> ------------------------
>   klass = String
>
>   case klass.name
>   when "String"
>     puts "I'm String class"
>   else
>     puts "I'm nothing..."
>   end

As you've found, Class#=== tells you if an object in an instance ofa class
(like is_a?), and this is how it's intended to be used.

You could in some cases *make* an instance (as long as the initializer doesn't need any arguments):

  case klass.new
  when String
     puts "I'm a String"
  end

But case is really intended for 'matches' tests. If you want 'equal to', then maybe you're better off with a simple Hash.

  KLASS_LOOKUP = {
    String => lambda { puts "I'm a String" },
  }
  KLASS_LOOKUP.default = lambda { puts "Something else" }

  klass = String
  KLASS_LOOKUP[klass].call