<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Ruby&#8217;s case statement uses ===</title>
	<atom:link href="http://johnleach.co.uk/words/402/rubys-case-statement-uses/feed" rel="self" type="application/rss+xml" />
	<link>http://johnleach.co.uk/words/402/rubys-case-statement-uses</link>
	<description>Stuff I think, see and do</description>
	<lastBuildDate>Mon, 14 May 2012 20:40:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: zoo</title>
		<link>http://johnleach.co.uk/words/402/rubys-case-statement-uses/comment-page-1#comment-152453</link>
		<dc:creator>zoo</dc:creator>
		<pubDate>Fri, 09 Dec 2011 12:39:20 +0000</pubDate>
		<guid isPermaLink="false">http://johnleach.co.uk/words/?p=402#comment-152453</guid>
		<description>Nope, that returns nil.</description>
		<content:encoded><![CDATA[<p>Nope, that returns nil.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bug</title>
		<link>http://johnleach.co.uk/words/402/rubys-case-statement-uses/comment-page-1#comment-144465</link>
		<dc:creator>Bug</dc:creator>
		<pubDate>Wed, 14 Sep 2011 02:16:57 +0000</pubDate>
		<guid isPermaLink="false">http://johnleach.co.uk/words/?p=402#comment-144465</guid>
		<description>The point, then, is that the method &#039;===&#039; is arbitrarily named, and might have been named more aptly.  For example, &#039;case_of?&#039; conveys that the object is being tested as belonging to a group of objects of which it is a special case.  2 is a special case of 2, just as it is a special case of Fixnum or Numeric, or even (1..7).</description>
		<content:encoded><![CDATA[<p>The point, then, is that the method &#8216;===&#8217; is arbitrarily named, and might have been named more aptly.  For example, &#8216;case_of?&#8217; conveys that the object is being tested as belonging to a group of objects of which it is a special case.  2 is a special case of 2, just as it is a special case of Fixnum or Numeric, or even (1..7).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bug</title>
		<link>http://johnleach.co.uk/words/402/rubys-case-statement-uses/comment-page-1#comment-144463</link>
		<dc:creator>Bug</dc:creator>
		<pubDate>Wed, 14 Sep 2011 02:11:44 +0000</pubDate>
		<guid isPermaLink="false">http://johnleach.co.uk/words/?p=402#comment-144463</guid>
		<description>The point of confusion is that &#039;===&#039; is a poor mnemonic for the particular kind of binary relation that it represents.  It gives the impression that it acts as an identity check or some other equivalence relation, with which Ruby&#039;s conception of case checking is incompatible.</description>
		<content:encoded><![CDATA[<p>The point of confusion is that &#8216;===&#8217; is a poor mnemonic for the particular kind of binary relation that it represents.  It gives the impression that it acts as an identity check or some other equivalence relation, with which Ruby&#8217;s conception of case checking is incompatible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Juan</title>
		<link>http://johnleach.co.uk/words/402/rubys-case-statement-uses/comment-page-1#comment-68240</link>
		<dc:creator>Juan</dc:creator>
		<pubDate>Tue, 29 Dec 2009 17:09:04 +0000</pubDate>
		<guid isPermaLink="false">http://johnleach.co.uk/words/?p=402#comment-68240</guid>
		<description>Do this =&gt;

my_type = Fixnum
case my_type
  when Fixnum:
    &quot;Fixed number&quot;
end</description>
		<content:encoded><![CDATA[<p>Do this =&gt;</p>
<p>my_type = Fixnum<br />
case my_type<br />
  when Fixnum:<br />
    &#8220;Fixed number&#8221;<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rahim</title>
		<link>http://johnleach.co.uk/words/402/rubys-case-statement-uses/comment-page-1#comment-63549</link>
		<dc:creator>Rahim</dc:creator>
		<pubDate>Sun, 30 Aug 2009 23:52:42 +0000</pubDate>
		<guid isPermaLink="false">http://johnleach.co.uk/words/?p=402#comment-63549</guid>
		<description>I think misread your initial post, I thought you were saying your second example didn&#039;t work as expected (which looking at it again looks like a pretty common pattern which made it all the more surprising).

Googling gives a few people who&#039;ve discussed the same behavior (http://www.justskins.com/forums/doing-a-case-on-class-23663.html, http://blog.jayfields.com/2007/03/ruby-operator.html), both of whom quote the ri docs for Module#=== which explains my observations :

------------------------------------------- Module#===
     mod === obj    =&gt; true or false
-----------------------------------------------------
     Case Equality---Returns +true+ if _anObject_ is an instance of
     _mod_ or one of _mod_&#039;s descendents. Of limited use for modules,
     but can be used in +case+ statements to classify objects by class.</description>
		<content:encoded><![CDATA[<p>I think misread your initial post, I thought you were saying your second example didn&#8217;t work as expected (which looking at it again looks like a pretty common pattern which made it all the more surprising).</p>
<p>Googling gives a few people who&#8217;ve discussed the same behavior (<a href="http://www.justskins.com/forums/doing-a-case-on-class-23663.html" rel="nofollow">http://www.justskins.com/forums/doing-a-case-on-class-23663.html</a>, <a href="http://blog.jayfields.com/2007/03/ruby-operator.html" rel="nofollow">http://blog.jayfields.com/2007/03/ruby-operator.html</a>), both of whom quote the ri docs for Module#=== which explains my observations :</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- Module#===<br />
     mod === obj    =&gt; true or false<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
     Case Equality&#8212;Returns +true+ if _anObject_ is an instance of<br />
     _mod_ or one of _mod_&#8217;s descendents. Of limited use for modules,<br />
     but can be used in +case+ statements to classify objects by class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rahim</title>
		<link>http://johnleach.co.uk/words/402/rubys-case-statement-uses/comment-page-1#comment-63547</link>
		<dc:creator>Rahim</dc:creator>
		<pubDate>Sun, 30 Aug 2009 23:38:13 +0000</pubDate>
		<guid isPermaLink="false">http://johnleach.co.uk/words/?p=402#comment-63547</guid>
		<description>=)

I read the docs and still couldn&#039;t see when that choice would help for case statements (perhaps because I was biased by your example...)

Another, at first glance odd, result this leads to is eg:

&gt;&gt; Fixnum === 2
=&gt; true
&gt;&gt; 2 === Fixnum
=&gt; false</description>
		<content:encoded><![CDATA[<p>=)</p>
<p>I read the docs and still couldn&#8217;t see when that choice would help for case statements (perhaps because I was biased by your example&#8230;)</p>
<p>Another, at first glance odd, result this leads to is eg:</p>
<p>&gt;&gt; Fixnum === 2<br />
=&gt; true<br />
&gt;&gt; 2 === Fixnum<br />
=&gt; false</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john</title>
		<link>http://johnleach.co.uk/words/402/rubys-case-statement-uses/comment-page-1#comment-63546</link>
		<dc:creator>john</dc:creator>
		<pubDate>Sun, 30 Aug 2009 22:45:02 +0000</pubDate>
		<guid isPermaLink="false">http://johnleach.co.uk/words/?p=402#comment-63546</guid>
		<description>Rahim, it&#039;s possible that it&#039;s optimized for case statement usage, which is pretty neat to be honest. Was just unexpected to me until I understood what was going on.

In fact, the docs suggest that:

http://www.ruby-doc.org/core/classes/Object.html#M000345</description>
		<content:encoded><![CDATA[<p>Rahim, it&#8217;s possible that it&#8217;s optimized for case statement usage, which is pretty neat to be honest. Was just unexpected to me until I understood what was going on.</p>
<p>In fact, the docs suggest that:</p>
<p><a href="http://www.ruby-doc.org/core/classes/Object.html#M000345" rel="nofollow">http://www.ruby-doc.org/core/classes/Object.html#M000345</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rahim</title>
		<link>http://johnleach.co.uk/words/402/rubys-case-statement-uses/comment-page-1#comment-63544</link>
		<dc:creator>Rahim</dc:creator>
		<pubDate>Sun, 30 Aug 2009 20:14:52 +0000</pubDate>
		<guid isPermaLink="false">http://johnleach.co.uk/words/?p=402#comment-63544</guid>
		<description>Any idea of the original rationale for the crazed implementation of Fixnum.=== ?

&gt;&gt; Fixnum === Fixnum
=&gt; false

doesn&#039;t seem like a good move to me!</description>
		<content:encoded><![CDATA[<p>Any idea of the original rationale for the crazed implementation of Fixnum.=== ?</p>
<p>&gt;&gt; Fixnum === Fixnum<br />
=&gt; false</p>
<p>doesn&#8217;t seem like a good move to me!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.105 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-18 02:19:20 -->

