<p>Simple question, but one that I've been curious about...is there a functional difference between the following two commands?</p>

<pre><code>String::class
String.class
</code></pre>

<p>They both do what I expect -- that is to say they return <code>Class</code> -- but what is the difference between using the <code>::</code> and the <code>.</code>?</p>

<p>I notice that on those classes that have constants defined, IRB's auto-completion will return the constants as available options when you press tab after <code>::</code> but not after <code>.</code>, but I don't know what the reason for this is...</p>

[{'answer_id': 43146, 'author': 'Joseph Daigle', 'author_id': 507, 'author_profile': 'https://Stackoverflow.com/users/507', 'pm_score': 6, 'selected': True, 'text': '<p>The <code>.</code> operator basically says "send this message to the object". In your example it is calling that particular member. The <code>::</code> operator "drills down" to the scope defined to the left of the operator, and then calls the member defined on the right side of operator.</p>\n\n<p>When you use <code>::</code> you have to be referencing members that are defined. When using <code>.</code> you are simply sending a message to the object. Because that message could be anything, auto-completion does not work for <code>.</code> while it does for <code>::</code>.</p>\n'}, {'answer_id': 48046, 'author': 'Peeja', 'author_id': 4937, 'author_profile': 'https://Stackoverflow.com/users/4937', 'pm_score': 4, 'selected': False, 'text': '<p>Actually, auto-completion does work for <code>.</code>.  The completion options are found by calling <code>#methods</code> on the object.  You can see this for yourself by overriding <code>Object.methods</code>:</p>\n\n<pre><code>&gt;&gt; def Object.methods; ["foo", "bar"]; end\n=&gt; nil\n&gt;&gt; Object.[TAB]\nObject.foo  Object.bar\n&gt;&gt; Object.\n</code></pre>\n\n<p>Note that this only works when the expression to the left of the <code>.</code> is a literal.  Otherwise, getting the object to call <code>#methods</code> on would involve evaluating the left-hand side, which could have side-effects.  You can see this for yourself as well:</p>\n\n<pre><code>[continuing from above...]\n&gt;&gt; def Object.baz; Object; end\n=&gt; nil\n&gt;&gt; Object.baz.[TAB]\nDisplay all 1022 possibilities? (y or n)\n</code></pre>\n\n<p>We add a method <code>#baz</code> to <code>Object</code> which returns <code>Object</code> itself.  Then we auto-complete to get the methods we can call on <code>Object.baz</code>.  If IRB called <code>Object.baz.methods</code>, it would get the same thing as <code>Object.methods</code>.  Instead, IRB has 1022 suggestions.  I\'m not sure where they come from, but it\'s clearly a generic list which isn\'t actually based on context.</p>\n\n<p>The <code>::</code> operator is (also) used for getting a module\'s constants, while <code>.</code> is not.  That\'s why <code>HTTP</code> will show up in the completion for <code>Net::</code>, but not for <code>Net.</code>.  <code>Net.HTTP</code> isn\'t correct, but <code>Net::HTTP</code> is.</p>\n'}]
['https://Stackoverflow.com/questions/43134', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4142/']