From: Rein Henrichs Date: 2010-06-11T16:55:07+09:00 Subject: Re: case when and class On 2010-06-11 00:29:24 -0700, Rein Henrichs said: > On 2010-06-10 23:41:05 -0700, Une B�vue said: > >> I've found in case / when if the case is about a class : >> >> case my_var.class >> when String then puts my_var >> when Array then my_var.each {|v| puts v} >> end >> >> doesn't work i do have to use : >> >> case my_var.class.to_s >> when 'String' then puts my_var >> when 'Array' then my_var.each {|v| puts v} >> end >> >> why ? >> >> (with ruby 1.9.x) > > Because of the behavior of the Module #== operator -- which you can > look it up at ruby-doc.org -- you can somply do this: > > case my_var > when String then puts my_var > when Array ... > end Woops, that should be Module#=== of course. -- Rein Henrichs http://puppetlabs.com http://reinh.com