Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Both are just methods called on objects. This means that the objects decide which means what. However, there are conventions in Ruby about how these are different. Usually, <code>==</code> is stricter than <code>===</code> - <code>a === b</code> will <i>almost</i> always be true if <code>a == b</code> is. The best place to read about this is <a href="http://ruby-doc.org/core/classes/Object.html" rel="noreferrer">http://ruby-doc.org/core/classes/Object.html</a>. Scroll down to the different sections about <code>==</code> and <code>===</code>. Here are some of the conventions I know about:</p> <ul> <li><code>==</code>, when applied to plain <code>Object</code>s, will only be true if one is exactly the same as the other - if they are stored in the same memory location (this is how Ruby works internally). If the arguments are of types other than Object, though, this method will usually be overridden.</li> <li><code>equal?</code> is just like <code>==</code> for plain <code>Object</code>s, but will never be overridden by subclasses.</li> <li><code>===</code> is used for: <ul> <li>an <code>is_a?</code> alternative, backwards. <code>String === 'str'</code> is true.</li> <li>matching regexes. <code>/s[at]r*/ === 'str'</code> is true.</li> </ul></li> </ul> <p>You can find the specific meaning of <code>===</code> for various classes in the documentation for those classes, for example, the <code>Range</code> version is here (a synonym for <code>include?</code>): <a href="http://ruby-doc.org/core/classes/Range.html#M000691" rel="noreferrer">http://ruby-doc.org/core/classes/Range.html#M000691</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload