<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>&lt;p&gt;Hi Sirs.&lt;/p&gt; &lt;p&gt;There is a difference between a bunch of methods that appear that they to the same job, but they won't.&lt;/p&gt; &lt;p&gt;The methods &lt;em&gt;instance_of?&lt;/em&gt;, &lt;em&gt;is_a?&lt;/em&gt; and &lt;em&gt;kind_of?&lt;/em&gt; do related jobs, but not the same job.&lt;/p&gt; &lt;p&gt;For example &lt;em&gt;is_a?&lt;/em&gt; and &lt;em&gt;kind_of?&lt;/em&gt; do the same job, they return true if the caller is an instance of the method argument, if the caller is an instance of every superclass in his inheritance tree or if the argument method is a module included in the caller.&lt;/p&gt; &lt;p&gt;The &lt;em&gt;instance_of?&lt;/em&gt; is more specific, it returns true just if the caller is an instance of the method argument.&lt;/p&gt;  &lt;p&gt;Let me show some examples:&lt;/p&gt;  

&lt;pre&gt;&lt;span class=&quot;keyword&quot;&gt;module &lt;/span&gt;&lt;span class=&quot;module&quot;&gt;Hand&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;class &lt;/span&gt;&lt;span class=&quot;class&quot;&gt;Animal&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;class &lt;/span&gt;&lt;span class=&quot;class&quot;&gt;Mamal&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;Animal&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;Hand&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;class &lt;/span&gt;&lt;span class=&quot;class&quot;&gt;Dog&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;Mamal&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;ident&quot;&gt;dog&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;Dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;new&lt;/span&gt;

&lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;instance_of?&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;comment&quot;&gt;# true&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;instance_of?&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Mamal&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;comment&quot;&gt;# false&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;instance_of?&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Animal&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;comment&quot;&gt;# false&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;instance_of?&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Hand&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;comment&quot;&gt;# false&lt;/span&gt;

&lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;is_a?&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;comment&quot;&gt;# true&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;is_a?&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Mamal&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;comment&quot;&gt;# true&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;is_a?&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Animal&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;comment&quot;&gt;# true&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;dog&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;is_a?&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Hand&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;comment&quot;&gt;# true &lt;/span&gt;

&lt;/pre&gt;

&lt;p&gt;Remember that &lt;em&gt;is_a?&lt;/em&gt; and &lt;em&gt;kind_of?&lt;/em&gt; do the same job.&lt;/p&gt; &lt;p&gt;See you.&lt;/p&gt;</body>
  <created-at type="datetime">2008-10-28T03:55:15Z</created-at>
  <id type="integer">36</id>
  <permalink>difference-between-is_a-and-instance_of</permalink>
  <title>Difference between is_a? and instance_of?</title>
  <updated-at type="datetime">2008-11-13T19:50:56Z</updated-at>
  <user-id type="integer">3</user-id>
</post>
