Hi --

On Fri, 19 Aug 2005, Daniel Schierbeck wrote:

> Could anyone explain to me why this isn't working?
>
> 	# returns 'no'
> 	case :foo.class
> 	  when Symbol then
> 	    puts 'yes'
> 	  else
> 	    puts 'no'
> 	end
>
> .... when this does
>
> 	# returns 'yes'
> 	case :foo.class.object_id
> 	  when Symbol.object_id then
> 	    puts 'yes'
> 	  else
> 	   puts 'no'
> 	end
>
> I'm puzzled...

:foo.class is Symbol.  In your first case statement, you're asking
whether Symbol is an instance of... Symbol.  It isn't: it's an
instance of Class.

What you want is:

   case :foo
   when Symbol    # i.e., if an instance of Symbol

etc.

The second case statement gives you 'yes' because the numbers match,
and the way numbers get compared in case statements isn't affected by
where those numbers come from.


David

-- 
David A. Black
dblack / wobblini.net