From: Josh Cheek Date: 2010-07-06T20:29:32+09:00 Subject: Re: WTF? Case statement disfunctional? --001636c5a329ca42af048ab65d60 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Jul 6, 2010 at 6:21 AM, Pieter Hugo wrote: > Hi > > I have a simple problem with the class of an object not being recognised > by the case statement. Am I just being an idiot again or is there > something more sinister going on here? > > a=1 > case a.class > when Fixnum > puts "It's a number silly" > else > puts "Can't figure it out" > end > > This snippet of code returns "Can't figure it out" which is just wrong? > > a.is_a? Fixnum => true and a.class => fixnum and a.class == Fixnum => > true, so why dont my case statement work? > > case a.class.to_s > when "Fixnum" > ... > > does the trick, but it just offends my aesthetics. > > Any ideas? Comments? > > Regards > > Pieter Hugo > South Africa > -- > Posted via http://www.ruby-forum.com/. > > Change it to a = 1 case a when Fixnum puts "It's a number silly" else puts "Can't figure it out" end Case statement turns into === and Fixnum === Fixnum is false, however, Fixnum === 1 is true --001636c5a329ca42af048ab65d60--